Mac安裝python2和python3,並配置

月下、山人發表於2020-12-27

1、下載

分別下載python2.X和python3.X

2、新增路徑

將python2、3到路徑新增到bash_profile中(以安裝到python2和anaconda3為例,一定要填寫正確到python路徑)

# Setting PATH for Python 2.X
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.X
PATH="/Users/hlj/opt/anaconda3/bin:$PATH"

3、宣告

將python指令宣告到具體路徑

alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/Users/hlj/opt/anaconda3/bin/python3.8'
alias python=python3

4、重新整理

source ~/.bash_profile
source ~/.bashrc 

完成後,控制檯輸入python2或python,進入python2.7環境中;輸入python3,進入python3.8環境中。

致謝
https://www.cnblogs.com/dylancao/p/10234094.html

相關文章