前言:mac系統(tǒng)自帶python篱竭,不過以當(dāng)前mac系統(tǒng)的最新版本為例毙籽,自帶的python版本都是2.版本路狮,雖然不影響老版本項目的運(yùn)行虫啥,但是python最新的3.版本的一些語法與2.*版本并不相同,網(wǎng)上的教程大神們也肯定都更新出了最新版的教程奄妨,我們不論是學(xué)習(xí)還是使用涂籽,當(dāng)然用最新版會更好一點。
轉(zhuǎn)載請注明出處http://www.cnblogs.com/meng1314-shuai/p/9031686.html
1砸抛、在安裝最新版Python3.*之前评雌,我們先熟悉一下系統(tǒng)自帶的python。
Mac系統(tǒng)自帶python路徑為/System/Library/Frameworks/Python.framework/Version,我們先來打開目錄看一下:
我們看到這里有多個python版本直焙,而在Current目錄下存放的是系統(tǒng)當(dāng)前的python版本景东。
mac既然自帶了python,當(dāng)然肯定配置好了python的全局命令奔誓,我們直接在終端運(yùn)行:
運(yùn)行正常渗常。到這里也差不多對mac系統(tǒng)自帶的python有所了解一姿,接下來我們開始安裝最新版本的python尼摹。
2奴烙、開始安裝(這里我們使用神器homebrew,還不熟悉此神器的小伙伴請自行百度蜕煌,也可點擊鏈接直接前往下載)
安裝前先搜索一下是否已經(jīng)存在python3的包:
已經(jīng)存在派阱,我們可以直接安裝了:
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
angular-cli fluent-bit links postgresql@9.6 texmath
byacc fn mlt qcachegrind tile38
caddy ipython osrm-backend rhino wtf
cfitsio ipython@5 postgresql siril
cfssl libpq postgresql@9.4 sundials
dnscrypt-proxy libpqxx postgresql@9.5 synfig
==> Installing dependencies for python: ****sphinx-doc****, ****gdbm****, ****openssl****, ****sqlite****, ****xz
==> Installing python dependency: ****sphinx-doc
==> Downloading https://homebrew.bintray.com/bottles/sphinx-doc-1.7.4.high_sierr
######################################################################## 100.0%
==> Pouring sphinx-doc-1.7.4.high_sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because this formula is mainly used internally by other formulae.
Users are advised to use pip
to install sphinx-doc.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"' >> ~/.bash_profile
==> Summary
?? /usr/local/Cellar/sphinx-doc/1.7.4: 2,642 files, 36.8MB
==> Installing python dependency: ****gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.14.1_1.high_sierra.b
######################################################################## 100.0%
==> Pouring gdbm-1.14.1_1.high_sierra.bottle.tar.gz
?? /usr/local/Cellar/gdbm/1.14.1_1: 20 files, 555.7KB
==> Installing python dependency: ****openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.high_sierr
######################################################################## 100.0%
==> Pouring openssl-1.0.2o_1.high_sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
==> Summary
?? /usr/local/Cellar/openssl/1.0.2o_1: 1,791 files, 12.3MB
==> Installing python dependency: ****sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.23.1.high_sierra.b
######################################################################## 100.0%
==> Pouring sqlite-3.23.1.high_sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/sqlite/lib
CPPFLAGS: -I/usr/local/opt/sqlite/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig
==> Summary
?? /usr/local/Cellar/sqlite/3.23.1: 11 files, 3MB
==> Installing python dependency: ****xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.high_sierra.bottle
######################################################################## 100.0%
==> Pouring xz-5.2.4.high_sierra.bottle.tar.gz
?? /usr/local/Cellar/xz/5.2.4: 92 files, 1MB
==> Installing ****python
Warning: Building python from source:
The bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install
==> Downloading https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/python/3.6.5 --enable-ipv6 --dataroot
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python/3.6.5
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python/3.6.5/sha
==> Downloading https://files.pythonhosted.org/packages/72/c2/c09362ab29338413ab
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/5d/c1/45947333669b31bc6b
######################################################################## 100.0%
==> make html
Error: An unexpected error occurred during the brew link
step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
所有的包都下載完畢,但是我們卻發(fā)現(xiàn)最后報了兩條錯誤幌绍,大概意思是公式已經(jīng)建立颁褂,但是在創(chuàng)建連接的時候因為沒有權(quán)限而發(fā)生意外錯誤。在報錯信息里我們看到一個目錄/usr/local/Frameworks傀广,我們先去找一下這個目錄:
發(fā)現(xiàn)這個目錄竟然不存在颁独,那我們就來手動創(chuàng)建一個:
創(chuàng)建好目錄之后,再來解決權(quán)限問題:
不報錯即為修改成功伪冰,修改好權(quán)限之后誓酒,還需要手動執(zhí)行一下安裝時未完成的創(chuàng)建連接:
連接成功。咱們來查看一下當(dāng)前系統(tǒng)下的python3的信息:
發(fā)現(xiàn)python3被安裝到了/usr/local/bin/python3目錄下,有興趣的小伙伴自行前往查看想過配置文件靠柑。
到這里python3的安裝就算完成了寨辩,不過可能有小伙伴已經(jīng)發(fā)現(xiàn),不管是在終端運(yùn)行python -V查看版本號還是直接運(yùn)行python啟動python命令行模式歼冰,默認(rèn)的python版本還是系統(tǒng)自帶的2.版本靡狞。其實這時候只運(yùn)行命令時需要把python改為python3就行了,當(dāng)然隔嫡,有興趣的小伙伴也可以嘗試配置一下默認(rèn)版本甸怕,把當(dāng)前系統(tǒng)的默認(rèn)版本修改為3.版本。知乎上已經(jīng)貼出了各種各樣的方法腮恩,我這里就不多做贅述了梢杭。
轉(zhuǎn)載請注明出處http://www.cnblogs.com/meng1314-shuai/p/9031686.html