【问题标题】:python and ipython pointing towards different installations after brew update and upgradepython和ipython在brew更新和升级后指向不同的安装
【发布时间】:2017-08-18 06:30:15
【问题描述】:

我使用的是 macOS Sierra 10.12.6

今天我跑步

brew update
brew upgrade

它升级了一堆包和安装,包括 python。升级后,ipython 指向正确的安装,python 没有。例如:

当我输入时:

$ which python
/usr/bin/python

这样:

$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

但是:

$ which ipython
/usr/local/bin/ipython

这样

$ ipython
Python 2.7.13 (default, Aug 17 2017, 16:42:26)
Type "copyright", "credits" or "license" for more information.

或:

$ which pip
/usr/local/bin/pip

这也很好。

当然,我的.bash_profile 包括:

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

和:

$ echo $PATH
/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

运行brew upgrade后,我今天还安装了命令行工具:

xcode-select --install 

因为它是在升级过程中被推荐的,但我怀疑这与问题有什么关系(?)

我试过了

$ brew link python
Warning: Already linked: /usr/local/Cellar/python/2.7.13_1
To relink: brew unlink python && brew link python

然后brew unlink python && brew link python

但问题依然存在。

总结:如何使安装保持一致?或如何让 python 指向正确的安装?

编辑

brew upgrade 期间,它同时安装了python2 和python3。要访问这些安装,您需要指定版本,因此:

$ which python
/usr/bin/python

$ which python2
/usr/local/bin/python2

$ which python3
/usr/local/bin/python3

请注意,在运行 brew upgrade 之前我没有 python3。

【问题讨论】:

  • 您可能想试试virtualenv
  • 你好@BarryLau。谢谢,但是我的安装非常干净(我会说),直到今天,在我设置的许多 Mac 中,我都没有遇到任何问题。 brew install python 加上 export PATH=/usr/local/bin:$PATH 在我的 .bash_profile 中完成工作。我在其他情况下使用过 virtualenv,但在这里它并不能解决我的问题。无论如何,谢谢。
  • 检查this。显然,brew 目前只提供 2.7.10。尝试下载source code并自己编译。
  • 升级时会安装 2.7.13。检查这个:ls /usr/local/Cellar/python 返回2.7.13_1,如果你在我的问题中看到brew link python 命令,你会看到它指向 2.7.13

标签: python macos homebrew


【解决方案1】:

可以通过调用找到解决方案:

brew info python

然后就可以阅读了

==> 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="/usr/local/opt/python/libexec/bin:$PATH"

所以简单地添加:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

~/.bash_profile 文件

这样就解决了问题。

【讨论】:

  • @bfontaine 非常感谢,实际上我的问题可能应该被标记为重复,因为我遇到了同样的问题,但遇到的方式不同。你的回答也很好。仅在安装/卸载两个小时后,我才想到要做brew info python,这就是解决方案:) 再次感谢
猜你喜欢
  • 2018-01-15
  • 1970-01-01
  • 2023-03-15
  • 2014-01-12
  • 2022-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-02
相关资源
最近更新 更多