brew-installed Python不会覆盖系统python

我刚刚使用brew在OS X上安装
Python 3. python3命令现在使用brew Python 3.6启动解释器,但是python仍然使用默认系统Python 2.7打开解释器.

我的理解是,默认情况下,brew Python现在应该覆盖系统Python. (即,见Order of /usr/bin and /usr/local/bin and more in $PATH).在我的PATH中,/usr/local/bin位于/usr/bin之前,因此它不应该是PATH问题.我试过重启终端,没有任何效果.

如果相关,这是我的完整PATH.

/Users/**/.rvm/gems/ruby-1.9.3-p362/bin:/Users/**/.rvm/gems/ruby-1.9.3-p362@global/bin:/Users/**/.rvm/rubies/ruby-1.9.3-p362/bin:/Users/**/.rvm/bin:/Users/**/.rvm/bin:/Users/**/Python/PmagPy/programs/conversion_scripts2/:/Users/**/Python/PmagPy/programs/conversion_scripts/:/Users/**/Python/PmagPy/programs:/usr/local/heroku/bin:./bin:/usr/local/sbin:/usr/local/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

为什么brew不优先使用?我该如何修复(或排除故障)?如果我找不到另一个选项,我可以创建一个别名,但我更愿意了解正在发生的事情并找到问题的根源.

更新:

我检查了“可能重复”的问题,但我的问题似乎不是一个链接问题:

 ~ brew link --overwrite --dry-run python
Warning: Already linked: /usr/local/Cellar/python/3.6.4_4
To relink: brew unlink python && brew link python
 ~ 

最佳答案 TL; DR将以下内容添加到.bash_profile(或等效文件)中:

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

说明

看来python通过自制程序现在处理方式不同(见https://docs.brew.sh/Homebrew-and-Python).

  • python3 points to Homebrew’s Python 3.x (if installed)
  • python2 points to Homebrew’s Python 2.7.x (if installed)
  • python points to Homebrew’s Python 2.7.x (if installed) otherwise the macOS system Python. Check out brew info python if you wish to add
    Homebrew’s 3.x python to your PATH.

检查brew信息python提示你需要做什么:

Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /usr/local/opt/python/libexec/bin

提示你因此必须在路径中的/usr/bin之前添加/usr/local/opt / python / libexec / bin(而不是/usr/local/bin,如某些来源所述,例如https://docs.python-guide.org/starting/install3/osx/)

另见https://github.com/Homebrew/homebrew-core/issues/15746

点赞