Mac OS Python 環境搭建

Mac OS 默認自帶了python 2.7.16,這裏我們要使用最新的python3,採用brew安裝,或者從python官網直接下載安裝也可以。

## 官網:https://www.python.org/

輸入 python 命令,可以看到當前默認的python信息。

(2.7安裝位置爲:/usr/bin/python2.7,軟連接 python命令指向2.7,因此後續要調整配置文件,將終端命令python指向3.11)

python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

使用brew安裝python 3.11

brew search python
brew install [email protected]

安裝完成後的信息顯示如下,包括默認安裝路徑等。

安裝完成後,可以看到默認的安裝路徑爲:/usr/local/bin/python3

python3 -> ../Cellar/[email protected]/3.11.2_1/bin/python3
python3.11 -> ../Cellar/[email protected]/3.11.2_1/bin/python3.11

打開終端配置文件,編輯如下,修改命令,完成後刷新配置文件 source ~/.zshrc

vim ~/.zshrc
## 在結尾添加以下代碼
alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7' 
alias python3='/usr/local/Cellar/[email protected]/3.11.2_1/bin/python3.11' 
alias python=python3

輸入名稱測試。

# python 3.11
python -V
# python 2.7
python2 -V

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章