有兩種安裝方法:
$brewinstall python
如果出錯(cuò)的話前面加上sudo
方法一安裝的是python2.7
方法二:從官網(wǎng)下載安裝最新版本(本次安裝的內(nèi)容)
官網(wǎng)地址:https://www.python.org/download,下載安裝最新版的python ,安裝簡(jiǎn)單,一路點(diǎn)擊OK;不便之處是后續(xù)卸載維護(hù)需要手動(dòng)進(jìn)行。
可以用這個(gè)命令查看python3安裝的位置:
$which python3
安裝完成后在終端中鍵入python3來(lái)驗(yàn)證安裝是否成功.
打開(kāi)Mac終端,輸入“python3”,回車(chē),查看是否是自己裝的Python版本(如果Mac系統(tǒng)版本是10.8—10.11,默認(rèn)自帶的是Python2.7)。輸入Python3后,看到顯示【>>>】,說(shuō)明已經(jīng)在Python的交互環(huán)境中了,可以正常使用。
這里安裝的是pip3。
安裝了python3之后,會(huì)有pip3
注意:
1. 使用pip install XXX
新安裝的庫(kù)會(huì)放在這個(gè)目錄下面
python2.7/site-packages
2. 使用pip3 install XXX
新安裝的庫(kù)會(huì)放在這個(gè)目錄下面
python3.6/site-packages
如果使用python3執(zhí)行程序,那么就不能import python2.7/site-packages中的庫(kù)
pip3 是一個(gè)安裝和管理 Python3 包的工具,pip 是一個(gè)安裝和管理 Python 包的工具,python安裝包的工具有easy_install, setuptools, pip,distribute等。distribute是setuptools的替代品,是對(duì)標(biāo)準(zhǔn)庫(kù)disutils模塊的增強(qiáng),我們知道disutils主要是用來(lái)更加容易的打包和分發(fā)包,特別是對(duì)其他的包有依賴(lài)的包。distribute被創(chuàng)建是因?yàn)镾etuptools包不再維護(hù)了。而pip/pip3是easy_install的替代品。
$wget https://bootstrap.pypa.io/get-pip.py
如果沒(méi)有安裝wget可以去這里:https://ftp.gnu.org/gnu/wget/下載
可以輸入wget www.baidu.com 測(cè)試是否安裝成功
將所有內(nèi)容復(fù)制下來(lái),新建get-pip.py文件,將內(nèi)容拷貝粘貼進(jìn)去.
執(zhí)行命令行:
$ sudo python3 get-pip.py
執(zhí)行出錯(cuò):
The directory '/Users/xsnai/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
換成下列命令:
$sudo -H python3 get-pip.py
Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
執(zhí)行成功!
終端命令行輸入pip3檢測(cè)。
檢測(cè)結(jié)果:
Usage: pip <command> [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. search Search PyPI for packages. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). --log <path> Path to a verbose appending log. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort. --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to alternate CA bundle. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
國(guó)內(nèi)由于網(wǎng)絡(luò)原因,使用pip3或和pip安裝一些模塊會(huì)特別慢甚至無(wú)法下載,因此我們需要修改源到國(guó)內(nèi)的一些鏡像地址,特別感謝國(guó)內(nèi)無(wú)私奉獻(xiàn)的組織~
首先進(jìn)入HOME路徑:
cd ~
創(chuàng)建.pip目錄:
mkdir .pip
創(chuàng)建pip.conf文件:
touch pip.conf
大家可以用自己喜歡的編輯器打開(kāi)pip.conf文件,我現(xiàn)在使用的時(shí)v2ex的源,所以添加:
[global]
index-url = http://pypi.v2ex.com/simple
大家可以把index-url的值設(shè)置為自己實(shí)際源的地址.
至此pip3源修改成功,以后使用pip安裝模塊時(shí)都會(huì)從這個(gè)源去下載安裝,大家可以自行測(cè)試一下.
國(guó)內(nèi)有如下下載源:
清華:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中國(guó)科技大學(xué) https://pypi.mirrors.ustc.edu.cn/simple/
華中理工大學(xué):http://pypi.hustunique.com/
山東理工大學(xué):http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
臨時(shí)使用:
可以在使用pip/pip3的時(shí)候加參數(shù)-i https://pypi.tuna.tsinghua.edu.cn/simple
如:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider
這樣就會(huì)從清華這邊的鏡像去安裝pyspider庫(kù)。
永久修改,一勞永逸:
Linux下,修改 ~/.pip/pip.conf (沒(méi)有的話就創(chuàng)建一個(gè)文件夾及文件。文件夾要加“.”,表示是隱藏文件夾)
內(nèi)容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windows下,直接在user目錄中創(chuàng)建一個(gè)pip目錄,如:C:\Users\xx\pip,新建文件pip.ini。內(nèi)容同上。
PIL(Python Imaging Library)圖像處理模塊,在python3.X已經(jīng)替換為pillow模塊(文檔:http://pillow.readthedocs.org/en/latest/)。
直接使用pip3 install pillow即可安裝模塊,導(dǎo)入時(shí)使用from PIL import Image.
命令行如下:
$pip3 install pillow
執(zhí)行過(guò)程如下:
Collecting pillow Downloading Pillow-4.3.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.5MB) 100% |████████████████████████████████| 3.6MB 19kB/s Collecting olefile (from pillow) Downloading olefile-0.44.zip (74kB) 100% |████████████████████████████████| 81kB 13kB/s Building wheels for collected packages: olefile Running setup.py bdist_wheel for olefile ... done Stored in directory: /Users/xsnai/Library/Caches/pip/wheels/20/58/49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b Successfully built olefile Installing collected packages: olefile, pillow Successfully installed olefile-0.44 pillow-4.3.0
4句代碼實(shí)現(xiàn)漢字識(shí)別
from PIL import Image import pytesseract text=pytesseract.image_to_string(Image.open('denggao.jpeg'),lang='chi_sim') print(text)
需要先安裝兩個(gè)包,如果沒(méi)有安裝的話。
pip3 install PIL pip3 install pytesseract
還需要下載中文語(yǔ)言包tesseract-ocr
更多關(guān)于Mabook安裝Python最新版本(3.6.4)、GUI開(kāi)發(fā)環(huán)境、圖像處理、視頻處理環(huán)境請(qǐng)查看下面的相關(guān)鏈接
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。