郑重提示:使用Xcode的不要升级Mac自带Python

卸载

Mac自带Python2.7,想用Python3.5

  1. 删除Python2.7安装文件

    1
    sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
  2. 删除2.7版本的链接

    1
    sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
  3. 删除/user/bin/目录下2.7版本相关的符号链接

    1
    sudo rm /usr/bin/{pydoc,python,pythonw,python-config}
  4. 检测2.7版本是否删除完成
    到相关文件夹下查看文件是否删除,命令行输入‘python’是否有正确输出

安装

  1. 官网下载安装文件
    地址,按照步骤安装

  2. 移动安装文件
    默认的安装路径是/Library/Frameworks/Python.framework/Versions/3.5,需要移动到系统库中

    1
    sudo mv /Library/Frameworks/Python.framework/Versions/3.5 /System/Library/Frameworks/Python.framework/Versions
  3. 链接3.5版本

    1
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.5 /System/Library/Frameworks/Python.framework/Versions/Current
  4. 在/user/bin/目录下创建新的命令链接

    1
    2
    3
    4
    sudo 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. 修改用户目录的权限

    1
    sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.5
  2. 修改环境变量

    1
    PYTHON=$/System/Library/Frameworks/Python.framework/Versions/3.5/bin:$PATH

打开文件查看修改是否正确

1
open -e .bash_profile

  1. 检测是否安装成功
    命令行输入‘python’是否能输出正确信息



Published with Hexo and Theme by Kael
X