brew installed Python을 기본 Python으로 어떻게 사용합니까?
Mac OS X 10.6.2에서 Homebrew (fink 및 macport를 사용한 후)로 전환하려고합니다. 파이썬 2.7을 설치했습니다.
brew install python
문제는 Macport와 달리 python_select 유틸리티가없는 것 같습니다. 내 기본 mac python은 항상 기본값입니다
which python
나에게주세요
/usr/bin/python
그리고 /usr/bin/python
심볼릭 링크가 아닙니다
파이썬 양조 맛을 기본 파이썬으로 만들려면 어떻게해야합니까?
Homebrew를 사용하면 다음 명령이 더 나은 그림을 제공합니다.
brew doctor
산출:
==> / usr / bin은 / usr / local / bin 이전에 발생합니다. 이는 Homebrew에서 제공하는 프로그램 대신 시스템 제공 프로그램이 사용됨을 의미합니다. 예를 들어 이것은 문제입니다. brew 설치된 Python.
.bash_profile을 편집하여 $ PATH의 / usr / bin보다 먼저 / usr / local / bin을 넣으십시오.
참조 : Homebrew에서 Python을 심볼릭 링크하는 방법은 무엇입니까?
$ brew link --overwrite python
Linking /usr/local/Cellar/python/2.7.3... 28 symlinks created
$ which python
/usr/local/bin/python
빠른 수정:
- 열다
/etc/paths
- 줄 순서 변경 (가장 높은 우선 순위)
제 경우에는 /etc/paths
다음과 같습니다.
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
OSX의 경로에 대해 더 알고 싶다면이 기사가 상당히 유용하다는 것을 알았습니다.
http://muttsnutts.github.com/blog/2011/09/12/manage-path-on-mac-os-x-lion/
OSX High Sierra에 대해 "brew install python"을했습니다. 이 $PATH
있었다 /usr/local/bin
다른 경로 전에하지만 여전히 which python
시스템의 파이썬을 가리키는했다.
자세히 살펴보면에 python 실행 파일이 없음을 발견했습니다 /usr/local/bin
. 실행 파일 이름은 python2
입니다. 이 문제를 해결하려면 다음을 python
가리키는 기호 링크를 작성하십시오 python2
.
/usr/local/bin $: ln -s python2 python
자체 설치 홈브류에 의해 제안으로, 당신이를 추가해야합니다 .bashrc
또는 .zshrc
:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Homebrew는 "/ usr / bin"의 내용을 대체하지 않습니다. "/ usr / local / bin"을 "/ usr / bin"보다 앞에두고 "python"을 사용하면 "/ usr / local / bin / python"이 표시됩니다.
/ usr / bin / python (또는 / usr / bin / ruby)을 교체하는 것은 권장하지 않습니다.
python
공식은 이제 python3
(v3.6.5)를 사용하고 brew는 디렉토리 를 링크합니다 :
/usr/local/opt/python -> ../Cellar/python/3.6.5
또한 바이너리를 연결합니다 :
/usr/local/bin/python3 -> ../Cellar/python/3.6.5/bin/python3
그래도 계속 사용해야하는 경우 다음을 python2.x
사용하십시오.
brew install python@2
homebrew 's를 사용하려면 python
bash의 디렉토리를 PATH에 넣으십시오.
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
물고기의 경우 :
set -x PATH /usr/local/opt/python/libexec/bin $PATH
노트 :
- 이렇게하면 시스템 기본 버전의 그림자가 생깁니다.
python
- homebrew
/usr/local/share/python
는 이전 버전에서 Python을 연결하는 데 사용되었습니다 .
$ PATH를 수정하고 이것을 bashrc 또는 bash_profile에 추가하십시오.
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
more click here: Issue #89791
You need to edit your PATH environmental variable to make sure wherever the homebrew python is located is searched before /usr/bin. You could also set things up in your shell config to have a variable like PYTHON be set to your desired version of python and call $PYTHON
rather than python
from the command line.
Also, as another poster stated (and especially on mac) DO NOT mess with the python in /usr/bin to point it to another python install. You're just asking for trouble if you do.
I did brew install python
, my $PATH
was good, but still, which python
gave me the system installed one. Restarting the terminal fixed it.
I believe there are means to make homebrew python default, but in my opinion the proper way to solve a problem is not to mess with system python paths: it is better to create a virtualenv in which homebrew python would be default (by using virtualenv --python option). Using tools like python_select
is almost always a bad idea.
python
now points to python3
, if you need python 2
then do: brew install python@2
and then in your .zshrc or .bashrc file export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"
Now, pyhon --version
= Python 2.7.14 and python3 --version
= Python 3.6.4. That's the behavior I'm used to seeing in my terminal.
Just do:
brew install python
brew link python
After doing that, add this to your bashrc or bash_profile:
alias python='/usr/local/bin/python2'
Enjoy!
You can edit /etc/paths. Here is mine:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Then add a symlink for the python version. In my case
$ cd /usr/local/bin
$ ln -s python3 python
Voila!
Since High Sierra, you need to use:
sudo chown -R $(whoami) $(brew --prefix)/*
This is because /usr/local
can no longer be chowned
Add the /usr/local/opt/python/libexec/bin
explicitly to your .bash_profile
:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
After that, it should work correctly.
No idea what you mean with default Python. I consider it bad practice to replace the system Python interpreter with a different version. System functionality may depend in some way on the system Python and specific modules or a specific Python version. Instead install your custom Python installations in a safe different place and adjust your $PATH as needed in order to call you Python through a path lookup instead of looking for the default Python.
참고URL : https://stackoverflow.com/questions/5157678/how-do-i-use-brew-installed-python-as-the-default-python
'IT' 카테고리의 다른 글
런타임에 뷰를 다른 뷰로 대체하는 Android 레이아웃 (0) | 2020.05.29 |
---|---|
캐스케이드 삭제시 JPA 2.0 orphanRemoval = true VS (0) | 2020.05.29 |
SQL Server에서 저장 프로 시저 또는 함수의 마지막 변경 날짜를 확인하는 방법 (0) | 2020.05.29 |
잡히지 않은 구문 오류 : JSON.parse가있는 예기치 않은 토큰 (0) | 2020.05.29 |
알파벳순으로 목록을 정렬하려면 어떻게해야합니까? (0) | 2020.05.29 |