brew更新和升级后指向不同安装的python和ipython

时间:2017-08-17 16:37:52

标签: python macos homebrew

我在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。

1 个答案:

答案 0 :(得分:0)

可以通过调用:

找到解决方案
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文件

这解决了这个问题。