第一步: 下載當(dāng)前最新版本 Python3.6骤肛,
下載地址:https://www.python.org/downloads/
第二步: 安裝下載好的包钢属,安裝完成后的目錄如下:
/Library/Frameworks/Python.framework/Versions/3.6 ?
第三步: 移動 Python 的安裝目錄放祟。
原有的 python2.x 都在目錄:
/System/Library/Frameworks/Python.framework/Versions?
下叔收。所以需要將你安裝好的 3.6 移動到系統(tǒng)目錄中
sudo mv /Library/Frameworks/Python.framework/Versions/3.6 /System/Library/Frameworks/Python.framework/Versions ?
第四步: 改變 python 安裝目錄用戶組為:wheel尝江,因為查看系統(tǒng)原有 python2.7 對應(yīng)的用戶組都是:wheel,故需要將新安裝的 3.6 改為這個用戶組
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.6 ?
第五步: 修改 Python 當(dāng)前安裝目錄的符號鏈接客扎,查看原有系統(tǒng) python2.x 目錄中即:/System/Library/Frameworks/Python.framework/Versions祟峦,下有一個名為 Current,它其實是一個指向當(dāng)前版本的軟連接徙鱼。我們需要將當(dāng)前的鏈接刪除宅楞,重新指向到新安裝的 python3.6 上
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.6 /System/Library/Frameworks/Python.framework/Versions/Current ?
第六步: 在 /usr/bin 目錄下有 4 個 python 命令的符號鏈接,需要刪除這些舊的鏈接
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config ?
刪除后重新建立新的鏈接袱吆,這些鏈接的指向都是我們新安裝的 pyhon3.6
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.6/bin/pydoc3.6 /usr/bin/pydoc?
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.6/bin/pythonw3.6 /usr/bin/pythonw
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config /usr/bin/python-config ?
第七步: 更新系統(tǒng)配置文件厌衙,即 root 用戶下的 .bash_profile(或者.zshrc) 文件,也就是:/root/.bash_profile
vim .bash_profile ??
在其中插入如下內(nèi)容: PATH="/System/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH ?
退出并使其生效
source .bash_profile?
?第八步: 截止到現(xiàn)在绞绒,就算配置完成了婶希。關(guān)閉當(dāng)前的 console 再重新開啟一個,然后執(zhí)行:python --version , 查看得到的是否是 python3.6蓬衡。
(該文章轉(zhuǎn)載致 http://www.mamicode.com/info-detail-1863595.html)