安装过程homebrew install python3
本文主要介绍2.7切换到3.7。
如果没安装3.7,终端显示为:
technology-fly:~ lcm$ python3
-bash: python3: command not found
安装后显示为:
technology-fly:~ lcm$ python3
Python 3.7.2 (default, Jan 13 2019, 12:50:15)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
原理:修改两个环境变量
1,终端输入 open ~/.bash_profile
添加以下代码
# Setting PATH for Python 2.7
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.7.2
PATH="/usr/local/Cellar/python/3.7.2/bin:${PATH}"
保存信息,终端输入source ~/.bash_profile
2,终端输入 open ~/.bashrc
添加以下代码
alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/usr/local/bin/python3'
# alias python=python3
保存信息,终端输入source ~/.bashrc
即可