1. 程式人生 > >怎麼讓mac終端輸入python預設開啟python3

怎麼讓mac終端輸入python預設開啟python3

背景:mac os x預設安裝python2.7,所以雖然後來裝了python3.5,但在終端中輸入python -V,仍然顯示版本號是2.7。 

那麼,想在終端中輸入python,進入python3的環境要怎麼做呢?
***  1. 終端開啟.bash_profile檔案  ***
open ~/.bash_profile

***  2. .bash_profile檔案內容  ***
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH *** 3. 新增別名->最終檔案 *** alias python="/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5" *** 4. 終端中重新讀取.bash_profile檔案 *** source .bash_profile

此時,在終端中輸入python,應該就是python3的環境了。 

注意:新增時,路徑的雙引號。

原文連結:https://blog.csdn.net/monkey7777/article/details/52295611