如何升級mac的python版本升級
① 如何更新Mac自帶python
mac lion自帶的python是2.7版本的,有點兒低,要使用一些應用的時候還需要3.3以上的,這時可以用以下的方法更新mac自帶的python。
先去python的官網下載最新的python,並安裝好。現在要刪除mac自帶的python,如下:
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
把第一步里安裝好的Python目錄移到原本系統所持有的目錄位置。
sudo mv /Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions
第三步,修改文件所屬的Group
設置Group為wheel,原來系統自帶的就是這樣的。
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.3
第四步,更新一下Current的Link
在Versions的目錄里有一個Current的link,是指向當前的Python版本,原始是指向系統自帶的Python2.7.2,我們把它刪除後,link就失效了,所以需要重新鏈一下
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions/Current
第五步,重新鏈接可執行文件
1) 先把系統原來的執行文件刪掉
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config
2) 建立新的鏈接
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/pydoc3.3 /usr/bin/pydoc
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/pythonw3.3 /usr/bin/pythonw
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3m-config /usr/bin/python-config
最後,更新一下.bash_profile文件
cd ~
vim .bash_profile (只要能編輯就行)
插入新的Python路徑
# Setting PATH for Python 3.3
# The orginal version is saved in .bash_profile.pysave
PATH="/System/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}"
export PATH
打開命令行,輸入python,如下:
chenwgtekiMacBook-Pro:~ chenwg$ python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type 「help」, 「right」, 「credits」 or 「license」 for more information.
>>>