下載當前最新版本 Python3.6,下載地址:https://www.python.org/downloads/python
安裝下載好的包,安裝完成後的目錄以下:vim
/Library/Frameworks/Python.framework/Versions/3.6
移動 Python 的安裝目錄。原有的 python2.x 都在目錄:/System/Library/Frameworks/Python.framework/Versions 下。因此須要將你安裝好的 3.6 移動到系統目錄中bash
sudo mv /Library/Frameworks/Python.framework/Versions/3.6 /System/Library/Frameworks/Python.framework/Versions
改變 python 安裝目錄用戶組爲:wheel,由於查看系統原有 python2.7 對應的用戶組都是:wheel,故須要將新安裝的 3.6 改成這個用戶組python2.7
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.6
修改 Python 當前安裝目錄的符號連接,查看原有系統 python2.x 目錄中即:/System/Library/Frameworks/Python.framework/Versions,下有一個名爲 Current,它實際上是一個指向當前版本的軟鏈接。咱們須要將當前的連接刪除,從新指向到新安裝的 python3.6 上blog
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 命令的符號連接,須要刪除這些舊的連接io
sudo rm /usr/bin/pydoc sudo rm /usr/bin/python sudo rm /usr/bin/pythonw sudo rm /usr/bin/python-config
刪除後從新創建新的連接,這些連接的指向都是咱們新安裝的 pyhon3.6console
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
更新系統配置文件,即 root 用戶下的 .bash_profile 文件,也就是:/root/.bash_profileclass
vim .bash_profile
在其中插入以下內容:配置
PATH="/System/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}" export PATH
退出並使其生效file
source .bash_profile
截止到如今,就算配置完成了。關閉當前的 console 再從新開啓一個,而後執行:python --version , 查看獲得的是不是 python3.6。