【问题标题】:Installing Homebrew Python and linking安装 Homebrew Python 和链接
【发布时间】:2017-07-18 15:15:39
【问题描述】:

我需要使用 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 进行链接

输出是这样的:

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

同样使用python -V 它显示Python 2.7.10 尽管Homebrew 中的当前版本是Python 2.7.13

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

使用: macOS Sierra (10.12.5)

【问题讨论】:

标签: python-2.7 installation homebrew macos-sierra


【解决方案1】:

由于最近从版本 2.7.13_1 开始对 python2 的 Homebrew 公式进行了更改,Homebrew 不再为 python 创建到 Homebrew 版本的符号链接。

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

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

$ 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 中详细讨论了这一变化。

【讨论】:

    猜你喜欢
    • 2020-09-26
    • 2015-12-01
    • 1970-01-01
    • 2013-09-11
    • 2017-04-02
    • 1970-01-01
    • 2023-03-31
    • 2013-08-05
    • 2022-01-13
    相关资源
    最近更新 更多