IT story

homebrew를 사용하여 macOS에서 이전 버전의 Python 3을 어떻게 설치할 수 있습니까?

hot-time 2020. 7. 25. 10:25
반응형

homebrew를 사용하여 macOS에서 이전 버전의 Python 3을 어떻게 설치할 수 있습니까?


brew를 사용하여 macOS에서 이전 버전의 Python 3을 어떻게 설치할 수 있습니까?

이 명령으로 brew install python최신 버전의 Python 3 (현재 v3.7.0)을 얻었지만 마지막 버전의 Python 3.6 (현재 3.6.5)을 원합니다.

pyenv다른 파이썬 설치를 처리하는 데 도움이되는 다른 패키지에 대해 읽었 지만이 솔루션은 나에게 적합하지 않습니다.


짧은 답변

Python 3.6.5를 새로 설치하려면 다음을 사용하십시오.

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

긴 답변

Homebrew로 Python을 설치하는 데에는 두 가지 공식이 있습니다 : python@2python.
첫 번째는 Python 2이고 두 번째는 Python 3입니다.

참고 : 웹에서 python3Python 버전 3을 설치하기위한 공식 이름으로 언급 된 오래된 답변을 찾을 수 있습니다 python.

기본적으로 이러한 공식을 사용하면 해당하는 주요 버전의 Python 최신 버전을 설치할 수 있습니다. 따라서 3.6과 같은 부 버전을 직접 설치할 수 없습니다.

해결책

를 사용 brew하면 공식 주소를 사용하여 패키지를 설치할 수 있습니다 (예 : git 저장소).

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

지정해야하는 주소는 원하는 버전에 대한 공식 (python.rb)의 마지막 커밋에 대한 주소입니다. homebrew-core / Formula / python.rb의 히스토리를 보면 커 민트 식별자를 찾을 수 있습니다.

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

파이썬> 3.6.5

위의 링크에는 3.6.5 이상의 Python 버전에 대한 공식이 없습니다. (공식) 저장소의 관리자가 Python 3.7을 출시 한 후에는 Python 3.7의 레시피에만 업데이트를 제출합니다.

위에서 설명한 것처럼 homebrew에는 Python 2 (python @ 2)와 Python 3 (python) 만 있으며 Python 3.6에 대한 명시적인 공식은 없습니다 .

이러한 사소한 업데이트는 대부분의 경우와 대부분의 사용자와 관련이 없지만 대부분 3.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-dependenciesbrew install에 인수를 추가하십시오 .

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.7을 설치하는 것이 었습니다

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

To create Python 3.7 virtual environment.

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

To create Python 3.6 virtual environment

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~ $ 

I tried all the answers above to install Python 3.4.4. The installation of python worked, but PIP would not be installed and nothing I could do to make it work. I was using Mac OSX Mojave, which cause some issues with zlib, openssl.

What not to do:

  • Try to avoid using Homebrew for previous version given by the formula Python or Python3.
  • Do not try to compile Python

Solution:

  1. Download the macOS 64-bit installer or macOS 64-bit/32-bit installer: https://www.python.org/downloads/release/python-365/
  2. In previous step, it will download Python 3.6.5, if for example, you want to download Python 3.4.4, replace in the url above python-365 by python-344
  3. Download click on the file you downloaded a GUI installer will open
  4. If you downloaded python-365, after installation, to launch this version of python, you will type in your terminal python365, same thing for pip, it will be pip365

p.s: You don't have to uninstall your other version of Python on your system.


Edit:


I found a much much much better solution that work on MacOSX, Windows, Linux, etc.

  1. It doesn't matter if you have already python installed or not.
  2. Download Anaconda
  3. Once installed, in terminal type: conda init
  4. In terminal,create virtual environment with any python version, for example, I picked 3.4.4: conda create -n [NameOfYour VirtualEnvironment] python=3.4.4
  5. Then, in terminal, you can check all the virtual environment you ahave created with the command: conda info --envs
  6. Then, in terminal, activate the virtual environment of your choice with: conda activate [The name of your virtual environment that was shown with the command at step 5]

To solve this with homebrew, you can temporarily backdate homebrew-core and set the HOMEBREW_NO_AUTO_UPDATE variable to hold it in place:

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

I don't recommend permanently backdating homebrew-core, as you will miss out on security patches, but it is useful for testing purposes.

You can also extract old versions of homebrew formulae into your own tap (tap_owner/tap_name) using the brew extract command:

brew extract python tap_owner/tap_name --version=3.6.5

참고URL : https://stackoverflow.com/questions/51125013/how-can-i-install-a-previous-version-of-python-3-in-macos-using-homebrew

반응형