Python安装:Mac 使用brew 安装Python2 和 Python3
-
安装python
## python2 brew install python ## python3 brew install python3
-
出现错误
Error: An unexpected error occurred during the `brew link` step The formula built, but is not symlinked into /usr/local Permission denied @ dir_s_mkdir - /usr/local/Frameworks Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
-
解决
手动创建目录
$ sudo mkdir /usr/local/Frameworks $ sudo chown $(whoami):admin /usr/local/Frameworks
-
查看版本
$ which python /usr/bin/python $ python --version Python 2.7.16
-
设置环境变量
## 打开配置文件,如果没有就在~目录下面创建一个 $ open ~/.bash.profile
设置python环境变量路径
# Setting PATH for Python 2.7 系统自带python2 PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" - export PATH # Setting PATH for Python 3.7.5 brew安装的python3 PATH="/usr/local/Cellar/python/3.7.5/bin:${PATH}" ## 设置别名 注意目录看下是否正确 alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7' alias python3='/usr/local/Cellar/python/3.7.5/bin/python3' # alias python=python3
生效配置文件
source ~/.bash.profile
-
验证
## python 和 python2 都指向python2 $ python --version $ python2 --version $ python3 --version
©
著作权归作者所有,转载或内容合作请联系作者
喜欢的朋友记得点赞、收藏、关注哦!!!