代码之家  ›  专栏  ›  技术社区  ›  ePi272314

如何使用自制在MacOS中安装早期版本的python 3?

  •  102
  • ePi272314  · 技术社区  · 7 年前

    brew install python 我得到了最新版本的python 3(当前是v3.7.0),但我想要最新版本的python3.6(当前是3.6.5)。

    pyenv 这有助于处理不同的python安装,但这个解决方案不适合我。

    5 回复  |  直到 6 年前
        1
  •  205
  •   Clint Eastwood tk120404    6 年前

    简短的回答

    brew unlink python # ONLY if you have installed (with brew) another version of python 3
    brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
    

    brew info python           # To see what you have previously installed
    brew switch python 3.x.x_x # Ex. 3.6.5_1
    

    冗长的回答

    python@2 python

    注: python3 蟒蛇

    解决方案

    brew

    brew install https://the/address/to/the/formula/FORMULA_NAME.rb
    

    或者专门针对python 3

    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/COMMIT_IDENTIFIER/Formula/python.rb
    

    您可以通过查看homebrew core/formula/python.rb的历史记录来找到comnt标识符。

    https://github.com/Homebrew/homebrew-core/commits/master/Formula/python.rb

    在上面的链接中,您将找不到3.6.5以上版本的Python的公式。

    如上所述,使用自制,您只有python 2(python@2)和python 3(python)。 .

        2
  •  29
  •   amiabl Vlad Bezden    6 年前

    brew unlink python # If you have installed (with brew) another version of python
    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
    

    你可能会遇到

    Error: python contains a recursive dependency on itself:
      python depends on sphinx-doc
      sphinx-doc depends on python
    

    --ignore-dependencies BREW安装的参数。

    brew unlink python # If you have installed (with brew) another version of python
    brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
    
        3
  •  11
  •   philshem    6 年前

    brew install python3
    brew unlink python
    

    然后我使用上面的链接安装了python 3.6.5

    brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb --ignore-dependencies
    

    brew link --overwrite python .现在我在系统中有了所有的蟒蛇来创建虚拟环境。

    mian@tdowrick2~ $ python --version
    Python 2.7.10
    mian@tdowrick2~ $ python3.7 --version
    Python 3.7.1
    mian@tdowrick2~ $ python3.6 --version
    Python 3.6.5
    

    mian@tdowrick2~ $ virtualenv -p python3.7 env
    Already using interpreter /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
    Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
    New python executable in /Users/mian/env/bin/python3.7
    Also creating executable in /Users/mian/env/bin/python
    Installing setuptools, pip, wheel...
    done.
    mian@tdowrick2~ $ source env/bin/activate
    (env) mian@tdowrick2~ $ python --version
    Python 3.7.1
    (env) mian@tdowrick2~ $ deactivate
    

    mian@tdowrick2~ $ virtualenv -p python3.6 env
    Running virtualenv with interpreter /usr/local/bin/python3.6
    Using base prefix '/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6'
    New python executable in /Users/mian/env/bin/python3.6
    Not overwriting existing python script /Users/mian/env/bin/python (you must use /Users/mian/env/bin/python3.6)
    Installing setuptools, pip, wheel...
    done.
    mian@tdowrick2~ $ source env/bin/activate
    (env) mian@tdowrick2~ $ python --version
    Python 3.6.5
    (env) mian@tdowrick2~ $ 
    
        4
  •  1
  •   vincedjango    6 年前

    我尝试了上面所有的答案来安装python 3.4.4。python的安装工作正常,但是pip不会被安装,我也无能为力。我使用的是mac osx mojave,这会导致zlib、openssl出现一些问题。

    • 尽量避免在公式给出的早期版本中使用自制啤酒。 蟒蛇3
    • 蟒蛇

    1. MacOS 64位安装程序 以下内容: https://www.python.org/downloads/release/python-365/
    2. ,例如,如果要下载 ,在上面的URL中替换 巨蟒-344
    3. 如果你下载了 蟒蛇365 第365页

        5
  •  0
  •   Steven Peters    6 年前

    为了解决这个问题 homebrew homebrew-core 并设置 HOMEBREW_NO_AUTO_UPDATE

    cd `brew --repo homebrew/core`
    git checkout f2a764ef944b1080be64bd88dca9a1d80130c558
    export HOMEBREW_NO_AUTO_UPDATE=1
    brew install python
    

    您还可以使用 brew extract

    brew extract python tap_owner/tap_name --version=3.6.5