簡介:
Mac 自帶 Python2.7 版本,可以在終端輸入 python 進入 python 編譯模式。如果要安裝 Python3 需要手動安裝「本文以 Python3.7 為例進行講解」。
安裝
方式一:
1. 在終端輸入: brew install python3
2. 等待自動安裝完成,再進行配置
方式二:
1. 官網(wǎng):https://www.python.org/downloads/
2. 下載對應(yīng)版本,一路默認安裝,安裝完成如下圖:

3. 安裝完成,在終端輸入: python,還是之前默認版本,需要該配置才能更新為最新版本
配置
1. 在終端輸入:which python3.7,可查看快捷方式存在的路徑,如圖

2. 安裝路徑:/Library/Frameworks/Python.framework

3. 終端輸入:vi ~/.bash_profile
4. 直接 vi 打開進行編輯,編輯完保存
5. 中斷輸入:source ~/.bash_profile
6. 終端再次輸入:python ,查看默認版本為 3.7

7. 查看 Python 版本

8. pip 查看版本

卸載 Python
1. Python3 安裝完后,在系統(tǒng)中不同目錄下存在各種依賴關(guān)系,若需卸載,需要一步步無殘留完全卸載干凈。
2. 刪除Python 3.7 框架,打開終端,輸入
? ? ? ?sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.7
3. 刪除 Python 3.7 應(yīng)用目錄
? ? ? cd /Applications
? ? ? sudo rm -rf Python 3.7
4. 刪除/usr/local/bin 目錄下指向的Python3.7 的連接
? ? ? cd /usr/local/bin/
? ? ? ls -l /usr/local/bin
? ? ? rm Python3.7相關(guān)的文件和鏈接
? ? ? #Python3.7相關(guān)的文件和鏈接需要自行確認是否刪除
5. 刪除 Python 的環(huán)境路徑
? ? ? ?vi ~/.bash_profile
6. 確認python 是否已經(jīng)刪除
? ? ? ?python3.7
? ? ? ?-bash: python3.7: command not found
------------------------------------------------------------------------------------------
至此,Python 3.7 安裝及卸載都講完了,大家可以試試了。