mac下切换python版本2.x和3.x

导读:
mac本身自带python为2.x版本,但是我们普遍应用python3.x版本,安装完python3.x版本后,我们需要切换到3.x版本。
1.检查当前python版本
终端输入命令:python -V
在这里插入图片描述
2.确定自己python是哪两个版本
(1)终端查一下,命令如下:在这里插入图片描述
(2)上边方法查不到,没事,在下边第 步中直接看版本的路径也是一样

3、将系统python版本,默认只想python3
(1)修改系统文件.bash_profile
a.终端输入命令:open -e .bash_profile
b.加入如下内容:

# Setting PATH for Python 3.9
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH 

在这里插入图片描述
c.获取PATH路径
输入命令:which python3
d.保存.bash_profile
e.应用更新:source .bash_profile

(2)修改.bashrc文件,没有新建一个
a.打开.bashrc文件:open -e .bashrc
(新建:touch .bashrc)
b.输入的信息:

alias python2='/usr/bin/python2.7'
alias python3='/Library/Frameworks/Python.framework/Versions/3.9/bin/python3'
alias python=python3

在这里插入图片描述路径来源:
python2终端输入命令:which python2
python3终端输入命令:which python3
注:如果想切换为py2.x版本,bashrc里的 python指向python2,之后保存,即生效
c.应用修改后的文件,输入命令:source .bashrc
4、重新检查当前应用版本
终端输入:python -V在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/bigge_L/article/details/114013963
今日推荐