郑重提示:使用Xcode的不要升级Mac自带Python
卸载
Mac自带Python2.7,想用Python3.5
删除Python2.7安装文件
1
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
删除2.7版本的链接
1
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
删除/user/bin/目录下2.7版本相关的符号链接
1
sudo rm /usr/bin/{pydoc,python,pythonw,python-config}
检测2.7版本是否删除完成
到相关文件夹下查看文件是否删除,命令行输入‘python’是否有正确输出
安装
官网下载安装文件
地址,按照步骤安装移动安装文件
默认的安装路径是/Library/Frameworks/Python.framework/Versions/3.5,需要移动到系统库中1
sudo mv /Library/Frameworks/Python.framework/Versions/3.5 /System/Library/Frameworks/Python.framework/Versions
链接3.5版本
1
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.5 /System/Library/Frameworks/Python.framework/Versions/Current
在/user/bin/目录下创建新的命令链接
1
2
3
4sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.5/bin/pydoc3.5 /usr/bin/pydoc
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.5/bin/pythonw3.5 /usr/bin/pythonw
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5m-config /usr/bin/python-config
其他链接的修复同上
修改用户目录的权限
1
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.5
修改环境变量
1
PYTHON=$/System/Library/Frameworks/Python.framework/Versions/3.5/bin:$PATH
打开文件查看修改是否正确1
open -e .bash_profile
- 检测是否安装成功
命令行输入‘python’是否能输出正确信息