Mac OS X 10.9 預設帶了 Python 2.7,不過現在 Python 3.3.3 已問世,想用最新版就趕緊升級吧。基本步驟如下。
第 1 步:下載 Python 3.3
下載位址如下:
Python 3.3
裡面有 Windows 與 Mac OS X 的安裝程式,下載那個 64 位的安裝檔(現在大概沒人用 32 位的 Mac OS X 了吧)。
第 2 步:
安裝下載的 img 檔,裝好後目錄如下:
/Library/Frameworks/Python.framework/Versions/3.3
第 3 步:移動 Python 的安裝目錄。原安裝目錄見第 2 步,不過所有 Python 都在
/System/Library/Frameworks/Python.framework/Versions
目錄中,所以最好用下面的命令移一下(不移也行,但後面某些路徑需相應修改)。
sudo mv /Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions
第 4 步:把 Python 安裝目錄的用戶組改為 wheel
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.3
Python 2.7 的用戶組就是 wheel,3.3 也照葫蘆畫瓢吧!
第 5 步:修改 Python 當前安裝目錄的符號連結
在 /System/Library/Frameworks/Python.framework/Versions/ 目錄下有一個 Current,這是個指向當前 Python 版本的目錄符號連結,原本指向 2.7,現在要指向 3.3。所以先刪除 Current,再重建,命令如下:
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
第 6 步:刪除舊的命令符號連結
在 /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
第 7 步:重建新的命令符號連結
把第 6 步刪掉的連結用下面的命令重建,它們都指向 Python 3.3 了。
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
第 8 步:更新 /root/.bash_profile 中的路徑
cd ~ vim .bash_profile
在 .bash_profile 插入下面的內容即可
# 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
ok,現在重啟一下 Console,然後執行 python --version,看到的就是 Python 3.3.3。若在程式中需要取得版本,可用:
import platform
print(platform.python_version())
如果你還用了 PyDev 等 IDE,仍需更新一下相關路徑。
現在就能使用最新的 Python 3.3.3 了。
推薦閱讀:
《Python 開發技術詳解》.( 周偉, 宗傑).[高清 PDF 掃描版+隨書視頻+代碼] https://www.linuxidc.com/Linux/2013-11/92693.htm
Python 腳本獲取 Linux 系統資訊 https://www.linuxidc.com/Linux/2013-08/88531.htm
Python 網站檔案及資料庫備份腳本 https://www.linuxidc.com/Linux/2012-06/62346.htm
Python 檔案處理:讀取檔案 https://www.linuxidc.com/Linux/2013-08/88496.htm
如何發布自訂的 Python 模組 https://www.linuxidc.com/Linux/2013-08/88495.htm
Python 爬蟲多執行緒抓取代理伺服器 https://www.linuxidc.com/Linux/2013-07/87289.htm
Python 中 re(正則表達式)模組詳解 https://www.linuxidc.com/Linux/2013-08/88588.htm
Python 的詳細介紹:請點這裡
Python 的下載位址:請點這裡