赞
踩
新开一个 terminal 窗口,输入如下命令打开.bash_profile
:
$ vi ~/.bash_profile
检查是否存在如下设置,如果没有则添加:
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# 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
保存并使其生效:
$ wq! #强制保存
$ source ~/.bash_profile
打开.bashrc
$ vi ~/.bashrc
添加如下信息:
alias python2='/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/Library/Frameworks/Python.framework/Versions/3.X/bin/python3.X' #3.X为你的 python3 的版本
alias python=python3 # 将默认python 版本切换成 python3
保存并使其生效:
$ wq! #强制保存
$ source ~/.bashrc
$ python -V
#输出如下:
Python 3.7.3
修改 .bashrc
文件中的刚添加的最后一行,将
alias python=python3
改为
alias python=python2
保存并让文件生效,
$ wq
$ source ~/.bashrc
检测版本
$ python -V
#输出如下:
Python 2.7.2
这样就完成了版本切换。
$ which python /usr/bin/python $ which python3 > /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 $ python Python 2.7.10 (default, Aug 17 2018, 19:45:58) [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> $ python3 Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
关于软链,看这篇文章:5分钟让你明白“软链接”和“硬链接”的区别
$ unlink /usr/bin/python
以后输入 python 则会直接转为 python3
$ ln -s /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 /usr/bin/python
我是空谷,独立产品经理、全栈设计师、全栈工程师。
技术栈为 React/Dva/Umi/Node/Egg/Electron
欢迎扫码加我微信交流,备注来源:CSDN
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。