自酿的Python不会覆盖系统python [英] brew-installed Python not overriding system python

查看:112
本文介绍了自酿的Python不会覆盖系统python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just used brew to install Python 3 on OS X. The python3 command now starts the interpreter using brew Python 3.6, but python still opens the interpreter with the default system Python 2.7.

我的理解是,默认情况下,brew Python现在应该覆盖系统Python. (即,请参见/usr的顺序/bin和/usr/local/bin以及$ PATH 中的更多内容).在我的PATH中,/usr/local/bin位于/usr/bin之前,因此它不应该是PATH问题.我尝试重新启动终端,但没有任何效果.

My understanding was that, by default, brew Python should now override system Python. (I.e., see Order of /usr/bin and /usr/local/bin and more in $PATH). In my PATH, /usr/local/bin comes before /usr/bin, so it shouldn't be a PATH issue. I have tried restarting Terminal, with no effect.

这是我完整的PATH,以备不时之需.

Here is my full PATH in case that is relevant.

/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

为什么不酿造Python优先?我该如何解决(或排除故障)呢?如果找不到其他选项,则可以创建一个别名,但是我更愿意了解正在发生的事情并找到问题的根源.

Why isn't brew Python taking precedence? And how can I fix (or troubleshoot) this? If I can't find another option, I can create an alias, but I prefer to understand what's happening and get to the root of the problem.

更新:

我签出了可能重复"的问题,但我的问题似乎不是链接问题:

I checked out the "possible duplicate" question, but my issue doesn't appear to be a linking problem:

 ~ 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(或等效版本):

TL;DR Add the following to your .bash_profile (or equivalent):

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

说明

现在似乎通​​过自制程序处理的python的处理方式有所不同(请参见 https://docs.brew.sh /Homebrew-and-Python ).

It seems python via homebrew is now handled differently (see https://docs.brew.sh/Homebrew-and-Python).

  • python3指向Homebrew的Python 3.x(如果已安装)
  • python2指向Homebrew的Python 2.7.x(如果已安装)
  • python指向Homebrew的Python 2.7.x(如果已安装),否则指向macOS系统的Python.如果要添加,请签出brew info python 自制软件的3.x python插入您的PATH.
  • 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 info python提示您需要做什么:

Checking out brew info python hints at what you need to do:

未版本化的符号链接pythonpython-configpip等指向 python3python3-configpip3等已分别 安装到/usr/local/opt/python/libexec/bin

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,例如

The hint being that you therefore have to add /usr/local/opt/python/libexec/bin before /usr/bin in your path (not /usr/local/bin as stated in some sources e.g. https://docs.python-guide.org/starting/install3/osx/)

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

这篇关于自酿的Python不会覆盖系统python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆