1. 程式人生 > >更新mac自帶的python

更新mac自帶的python

1,刪除系統版本2.7

a,刪除系統版本

sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7

b,刪除當前版本

sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7

sudo rm /System/Library/Frameworks/Python.framework/Versions/Current

c,刪除cd /usr/bin;下的python相關檔案(此步驟沒必要執行!

find . -name "py*" -print| xargs rm -rf

2,下載需要的python版本並安裝。

3,連結庫版本及python相關檔案:

設定Group組為wheel,原來系統自帶的就是這樣:

sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.4

a, sudo mv /Library/Frameworks/Python.framework/Versions/3.4 /System/Library/Frameworks/Python.framework/Versions

b, sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4 /System/Library/Frameworks/Python.framework/Versions/Current

刪除原先執行檔案

c, sudo rm /usr/bin/pydoc

d, sudo rm /usr/bin/python

e, sudo rm /usr/bin/pythonw

f, sudo rm /usr/bin/python-config

建立新的連結:

g, sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/pydoc3.4 /usr/bin/pydoc

h, sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /usr/bin/python

i,  sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/pythonw3.4 /usr/bin/pythonw

j, sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config /usr/bin/python-config

4,更新使用者.bash_profile配置檔案:

cd ~

vim .bash_profile

# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH

5,驗證版本號:

python -V

6,可能遇到的問題:The orginal version is saved in .bash_profile.pysave

若python 版本沒有更新成功, 修改.bash_profile.pysave檔案path 路徑;