Homebrew를 사용하여 Mac에 Python 2와 3을 모두 설치하려면 어떻게해야합니까?
파이썬 2와 3 사이를 전환 할 수 있어야합니다. 경로를 엉망으로 만들고 문제를 일으키지 않기 위해 Homebrew를 사용하여 어떻게합니까? 지금은 Homebrew를 통해 2.7을 설치했습니다.
$ brew install pyenv
Bash 쉘에서 pyenv를 활성화하려면 다음을 실행해야합니다.
$ eval "$(pyenv init -)"
시작할 때 Bash를 자동으로 수행하려면 해당 행을에 추가하십시오 ~/.bash_profile. 1
용법:
pyenv를 설치하고 활성화하면 다른 버전의 파이썬을 설치하고 사용할 수있는 버전을 선택할 수 있습니다. 예:
$ pyenv install 2.7.5
설치 한 버전을 확인할 수 있습니다.
$ pyenv versions
그리고 다음 명령을 사용하여 파이썬 버전 사이를 전환 할 수 있습니다.
$ pyenv global 3.3.1
또한 다음을 사용하여 현재 디렉토리의 파이썬 버전을 설정할 수 있습니다.
$ pyenv local 3.5.2
다음을 실행하여 확인할 수 있습니다 python --version.
$ python --version
Python 3.5.2
1 pbrewv 설치시이 작업을 수행하도록 지시하는 Homebrew가 있었지만 메시지가 제거되었습니다 . Zsh 및 기타 셸의 경우 정확한 단계가 다를 수 있습니다.
두 버전을 동시에 설치할 수 있습니다.
Homebrew> = 1.5.0의 경우 :
2018 년 3 월 1 일부터 python공식이 Python 3.x로 업그레이드되고 python@2, 특히 Python 2.7에 대한 새로운 공식이 추가 될 예정입니다.
여기에서 변경 사항 발표 또는 Python 용 Homebrew 사용에 대한 최종 문서를 참조 하십시오 .
오래된 Homebrew의 경우 :
Python 2.x의 경우 :
brew install python
Python 3.x의 경우 :
brew install python3
이제 컴퓨터에 두 버전이 모두 설치되었습니다. 버전 2를 사용하려면 python실행 파일을 사용하십시오 . 버전 3을 사용하려면 python3실행 파일을 사용하십시오 .
현재 Homebrew는 Python 2 및 3에 대해 서로 다른 두 가지 공식을 제공 brew install python합니다. python3을 brew install python@2설치하고 python2를 설치합니다. Homebrew 문서에 대한 자세한 내용 :
https://docs.brew.sh/Homebrew-and-Python
현재 Homebrew를 통해 2.x를 설치 한 경우 Homebrew는 다음과 같은 메시지를 표시합니다.
Error: python 2.7.14 is already installed
To upgrade to 3.6.5, run `brew upgrade python`
당신이 실행하는 경우 :
brew upgrade python
당신은 할 수 있어야합니다 :
python --version
과
python3 --version
설치된 Python 2.x 및 3.x 버전을 확인하십시오.
또는 "python3"을 입력하여 최신 버전의 python3.x를 실행하고 "python"또는 "python2"를 설치하여 최신 설치된 2.x 버전을 실행할 수 있습니다.
두 가지를 모두 사용할 수있는 방법이 있지만 오늘날 가장 간단한 해결책은 pyenv 를 사용하는 것 입니다. pyenv를 사용하면 버전간에 쉽게 전환 할 수 있습니다. 다음은 내가 설정 한 작업입니다.
1 단계:
Mac에서 모든 파이썬 제거
brew uninstall --ignore-dependencies --force python
sudo rm -rf ~/miniconda3/
sudo rm -rf ~/.conda/
에서 다음을 제거하십시오 ~/.bash_profile
export PATH="/Users/ishandutta2007/miniconda3/bin:$PATH"
그리고 또한 다음에서 ~/.bashrc
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH export PYTHONPATH=/usr/local/lib/python2.7/site-packages/google:$PYTHONPATH alias python="/usr/bin/python"
2 단계 :
pyenv 및 필요한 Python 버전 설치
brew update
brew install pyenv
pyenv install 2.7
pyenv install 3.7.0
STEP3 :
추가 pyenv init로 bash_profile또는bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
STEP4 :
무엇을 설치했는지 확인
pyenv versions
시스템 (/Users/ishandutta2007/.pyenv/version에서 설정)
2.7
3.7.0
5 단계 :
기본값을 선택하십시오
pyenv global 3.7.0
프로젝트에 이전 버전이 필요한 경우 루트 폴더로 이동하여 실행하십시오.
pyenv local 2.7
asdf를 사용하십시오 !
asdf의 발라드
Once upon a time there was a programming language
There were many versions of it
So people wrote a version manager for it
To switch between versions for projects
Different, old, new.Then there came more programming languages
So there came more version managers
And many commands for themI installed a lot of them
I learnt a lot of commandsThen I said, just one more version manager
Which I will write insteadSo, there came another version manager
asdf version manager - https://github.com/asdf-vm/asdfA version manager so extendable
for which anyone can create a plugin
To support their favourite language
No more installing more version managers
Or learning more commands
https://github.com/asdf-vm/asdf
https://github.com/tuvistavie/asdf-python
https://github.com/asdf-vm/asdf-plugins
I thought I had the same requirement - to move between Python versions - but I achieved all I needed with only Python3.6 by building from source instead of using homebrew.
git clone https://git.<theThingYouWantToInstall>
Depending on the repo, check if there is MAKE file already setup for this option.
I was able to just go to https://www.python.org/downloads/mac-osx/ and download the latest python. It installed along side current python in my system.
Okay, I was struggling with my brew installation of Python3, because I didn't have pip3
sudo pip3 command not found
and so I did
brew uninstall --force --ignore-dependencies python3
and installed the regular Python 3.6.2 from official distribution and then I had pip3 and all components were ok.
'IT' 카테고리의 다른 글
| JQuery.trigger ( 'click')를 얻는 방법; (0) | 2020.06.25 |
|---|---|
| 완료하는 데 시간이 너무 오래 걸리는 경우 타임 아웃 기능 (0) | 2020.06.25 |
| 주어진 문자열이 Java에서 유효한 JSON인지 확인하는 방법 (0) | 2020.06.25 |
| Python 3에서 int를 바이트로 변환 (0) | 2020.06.25 |
| 부트 스트랩 경고 자동 닫기 (0) | 2020.06.25 |