mac电脑 Python2 升级 Python3

下载新版

首先进入到 Python 官网,下载最新版本 Python
https://www.python.org/downloads/mac-osx/

mac电脑 Python2 升级 Python3_第1张图片

下载后双击安装,装到默认的系统位置即可。装完后会自动写入环境变量的,打开终端,输入命令:

vim ~/.bash_profile

打开后在编辑器中可以看到已经存在了 Python 最新版本的配置,如下:

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

最需要在最后添加一行:

alias python="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7"

编辑配置的vim命令可参考:https://blog.csdn.net/Beamon__/article/details/106377979

保存退出,刷新:

source ~/.bash_profile

然后查看 Python 版本:

python --version

 

就可以看到当前已经引用了最新版本 Python。

参考文档:https://blog.csdn.net/luoyayun361/article/details/81607829

你可能感兴趣的:(其他)