Mac 系统同时安装python2 和python3
2018-07-07 本文已影响17人
wg689
很多教程反馈的先删除python2 再安装python3 的方法不合适,可能会造成xcode无法运行,所以最好还是让python2 和python3 共存
1.下载python最新版本
链接:https://www.python.org/downloads/mac-osx/
安装默认位置为: /Library/Frameworks/Python.framework/Versions/3.5/
![](https://img.haomeiwen.com/i1194882/770233ab44a58df6.png)
2.打开终端,修改~/.bash_profile文件,添加代码
打开~/.bash_profile
的方法 终端中输入open .bash_profile
即可 再open .
添加的代码如下:
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6"
2.1)切换python2 和python3 的方法如下:
![](https://img.haomeiwen.com/i1194882/bf5e12bb5b13f8b6.png)
3.重启终端或执行
source ~/.bash_profile
4)显示版本(大功告成)
![](https://img.haomeiwen.com/i1194882/f3812681f950c6e7.png)
5) 切换版本
![](https://img.haomeiwen.com/i1194882/f3faf613ede666e4.png)