我尝试在Mac OS X 10.6.2上切换到Homebrew(在使用fink和macport后)。我已经安装了python 2.7
brew install python
问题是,与Macport相反,似乎没有python_select实用程序,我的默认mac python总是默认的
which python
给我
/usr/bin/python
而且/usr/bin/python不是符号链接
我怎么做才能使python酿造风味成为我的默认python ?
我尝试在Mac OS X 10.6.2上切换到Homebrew(在使用fink和macport后)。我已经安装了python 2.7
brew install python
问题是,与Macport相反,似乎没有python_select实用程序,我的默认mac python总是默认的
which python
给我
/usr/bin/python
而且/usr/bin/python不是符号链接
我怎么做才能使python酿造风味成为我的默认python ?
当前回答
只做:
brew install python
brew link python
在此之后,将其添加到bashrc或bash_profile中:
alias python='/usr/local/bin/python2'
享受吧!
其他回答
您需要编辑您的PATH环境变量,以确保在/usr/bin之前搜索自制python所在的位置。你也可以在你的shell配置中设置一些东西,让一个像PYTHON这样的变量被设置为你想要的PYTHON版本,并从命令行调用$PYTHON而不是PYTHON。
另外,正如另一个帖子所述(特别是在mac上),不要混淆/usr/bin中的python,将其指向另一个python安装。你这样做是在自找麻烦。
您可以编辑/etc/paths以下是我的看法:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
然后为python版本添加符号链接。对我来说
$ cd /usr/local/bin
$ ln -s python3 python
拖鞋!
对于苹果的硅机器来说,路径略有不同。运行brew install python后,必须确保您的~/。zshrc使用正确的Homebrew路径:
# Homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
# Homebrew: Python
export PATH="/opt/homebrew/opt/python/libexec/bin:$PATH"
结果:
% which python
/opt/homebrew/opt/python/libexec/bin/python
% python --version
Python 3.9.9
% which pip
/opt/homebrew/opt/python/libexec/bin/pip
% pip -V
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
将/usr/local/opt/python/libexec/bin显式添加到.bash_profile:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
在那之后,它应该能正常工作。
只做:
brew install python
brew link python
在此之后,将其添加到bashrc或bash_profile中:
alias python='/usr/local/bin/python2'
享受吧!