1、mac自带一个2.7版本的python
MacBookPro:python wuxi$ which python /usr/bin/python
查看 python 版本
MacBookPro:python wuxi$ python --version Python 2.7.10
2、mac 安装python3版本
brew install python3
MacBookPro:bin wuxi$ which python3 /usr/local/bin/python3
python3 软链接
python3 -> ../Cellar/python/3.7.2_1/bin/python3
python3 -> ../Frameworks/Python.framework/Versions/3.7/bin/python3
查看最新python版本
MacBookPro:site-packages wuxi$ python3 --version Python 3.7.2
第三方包安装位置site-packages
/usr/local/lib/python3.7/site-packages
运行python3
exit()退出
MacBookPro:~ wuxi$ python3
Python 3.7.2 (default, Jan 13 2019, 12:51:54)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
3、配置环境变量
将python命令替换成python3
export Python_HOME=/usr/local/Cellar/python/3.7.2_1
// 全局命令行
export PATH=$Python_HOME/bin:$PATH
// python 指向python3
alias python="/usr/local/Cellar/python/3.7.2_1/bin/python3"
// pip 指向pip3
alias pip="/usr/local/Cellar/python/3.7.2_1/bin/pip3"
source /etc/profile
打开终端 执行 python ,修改成功
MacBookPro:bin wuxi$ python
Python 3.7.2 (default, Jan 13 2019, 12:51:54)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print(100 + 200 + 300)
600
>>> print(100 + 300)
400
>>> exit()
来源:CSDN
作者:tellmewsm
链接:https://blog.csdn.net/wx19900503/article/details/103756217