美文网首页
Mac 上安装Python2.7和Python3

Mac 上安装Python2.7和Python3

作者: Welman | 来源:发表于2018-12-27 18:00 被阅读20次

    1 安装Xcode

    xcode-select --install
    

    2 安装Homebrew

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    
    清华大学镜像
    cd "$(brew --repo)"
    git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
    
    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
    
    brew update
    
    

    3 安装Python

    接下来要正式进入安装Python的步骤了!
    首先,输入

    python --version
    打印出 Python 2.7.10 ,是mac自带的,不需要卸载
    

    开始安装:
    利用homebrew搜索Python

    brew search python
    

    会有如下结果:

    app-engine-python  gst-python         python ✔           wxpython
    boost-python       ipython            python-markdown    zpython
    boost-python3      ipython@5          python-yq
    boost-python@1.59  micropython        python@2 ✔
    
    ==> Casks
    awips-python              kk7ds-python-runtime      mysql-connector-python
    
    If you meant "python" specifically:
    It was migrated from homebrew/cask to homebrew/core.
    

    开始安装:

    brew install python
    
    brew install python3
    

    查看安装的目录 /usr/local/Cellar/

    4 设定路径$PATH (不和系统Python干扰)

    执行 
    1、echo $PATH
    打印出
    /usr/local/opt/gettext/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    
    打开 
    2、sudo vim /etc/paths
    系统会按以下顺序去索引
    /usr/local/bin:
    /usr/bin:
    /bin:
    /usr/sbin:
    /sbin
    
    

    5 安装完成,确认结果

    which python
    打印出  /usr/local/bin/python和/usr/local/bin/python3 说明安装正确
    

    如果想使用系统的Python,就输入

    /usr/bin/python
    

    转载自 https://blog.csdn.net/hou_manager/article/details/79555809
    个人怕忘记,所以简书上抄了一份过来,感谢分享。

    相关文章

      网友评论

          本文标题:Mac 上安装Python2.7和Python3

          本文链接:https://www.haomeiwen.com/subject/qlddlqtx.html