安装 Homebrew Python 并链接

Installing Homebrew Python and linking

我需要使用 Python 的 Homebrew 版本,而不是 Python 的系统版本。我全新安装了 macOS Sierra (10.12.5)。

我先安装了自制软件,然后使用 nano ~/.bash_profile 更新了 ~/.bash_profile。 然后我将其添加到文件中:

# Homebrew
export PATH=/usr/local/bin:$PATH

然后,我需要手动获取 ~/.bash_profile 文件以确保使用 source ~/.bash_profile.

重新加载更改

我使用 brew install python 安装了 python 并尝试使用 brew linkapps python

link

输出是这样的:

Warning: Already linked: /usr/local/Cellar/python/2.7.13_1
To relink: brew unlink python && brew link python
Gautams-Air:~ gautam$ which python
/usr/bin/python
Gautams-Air:~ gautam$ python -V
Python 2.7.10
Gautams-Air:~ gautam$ brew linkapps python
Warning: brew linkapps has been deprecated and will eventually be removed!

Unfortunately brew linkapps cannot behave nicely with e.g. Spotlight using
either aliases or symlinks and Homebrew formulae do not build "proper" .app
bundles that can be relocated. Instead, please consider using brew cask and
migrate formulae using .app's to casks.
Linking: /usr/local/opt/python/IDLE.app
Linking: /usr/local/opt/python/Python Launcher.app
Linked 2 apps to /Applications`

使用 which python 输出是: /usr/bin/python

应该是:/usr/local/bin/python

我也试过使用:brew unlink python && brew link python

虽然 Homebrew 中的当前版本是 Python 2.7.13

,但也使用 python -V 它显示 Python 2.7.10

如何使用 Homebrew 版本的 Python 而不是系统版本的 Python? - 如何进行 linking?

使用: macOS 塞拉利昂 (10.12.5)

由于从版本 2.7.13_1 开始的 python2 的 Homebrew 公式最近发生了变化,Homebrew 不再为 python 创建指向 Homebrew 版本的符号链接。

相反,它只安装和符号链接 python2。您将需要采取额外的步骤来使用它而不是 Python.

的系统版本

请参阅此软件包信息中的 "Caveats" 部分。下面是一个示例,但请注意,要导出的实际路径已生成,并且在您的计算机上可能有所不同。

$ brew info python2

... snip ...

=> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
  export PATH="<... some path ...>:$PATH"

... snip ...

编辑: Homebrew 在他们的 recent release notes.

中详细讨论了这一变化