Mac安装python2和python3,并配置

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

你可能感兴趣的:(Mac安装python2和python3,并配置)