Pip突然使用错误版本的Python [英] Pip suddenly using wrong version of Python
问题描述
在 os x 上使用 pip 有一个奇怪的问题.
Having a weird problem with pip on os x.
据我所知(快速查看我的 .bash_history 似乎可以确认)我最近没有对我的配置进行任何更改.唉,pip 命令似乎突然使用了与以前不同版本的 python.到目前为止,我使用命令 pip 来管理我的 python2 库和 pip3 来管理 python3 库.突然间,任何运行 pip install 的尝试都会失败,并出现诸如缺少打印语句周围的括号之类的错误.
As far as I can recall (and a quick look at my .bash_history seems to confirm) I have not made any recent changes to my configuration. Alas, the pip command seems to be suddenly using a different version of python than it was previously. Up until now I was using the command pip to manage my python2 libraries and pip3 to manage by python3 libraries. Suddenly, any attempts at running pip install fails with errors like missing parenthesis around print statements.
这是我试图找出问题的几个命令的结果:
Here is the result of a few commands I attempted to figure out the problem:
which pip > /usr/local/bin/pip
which pip3 > /usr/local/bin/pip3
which python > /usr/local/bin/python
python version > Python 2.7.11
pip --version > pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
因此,出于某种原因,pip 命令似乎从 PyPi2 数据库运行,但现在在 python3 中运行?任何想法如何解决这个问题?
So for some reason the pip command seems to be running from the PyPi2 database but in python3 now? Any ideas how to fix this?
推荐答案
我运行多个 Python 版本,因此也运行多个 pip 版本.
I run with multiple Python versions and thus multiple pip versions as well.
但是,每次更新 pip 时,您都会用更新的版本替换标准的 pip
命令.所以即使 pip3 install --upgrade pip
也会在你的系统中放入一个 /usr/local/bin/pip
,搞乱 Python 2 版本.
Everytime, however, you update pip, you'll replace the standard pip
command with the version you updated. So even pip3 install --upgrade pip
will put a /usr/local/bin/pip
in your system, messing up the Python 2 version.
相反,我将 pip 作为(可执行)模块运行:
Instead, I run pip as an (executable) module:
python3 -m pip search <package>
或
python2 -m pip search <package>
甚至
python3.5 -m pip search <package>
这保证您的 pip
版本始终与您要使用它的 Python 版本匹配.打字时间有点长,但我更喜欢它的明确性(我猜这遵循 Python 的 Zen).
This guarantees that your pip
version always matches the Python version you want to use it for. It's somewhat longer to type, but I prefer the expliciteness of it (which, I guess, follows the Zen of Python).
注意更新pip:
python3.5 -m pip install --upgrade pip
仍将在 /usr/local/bin/pip
中安装 Python 3.5 版本,但我只是忽略了这一点.请注意直接执行 pip
的(shell)脚本.
will still install a Python 3.5 version in /usr/local/bin/pip
, but I'm simply ignoring that. Just beware of (shell) scripts that execute pip
directly.
这篇关于Pip突然使用错误版本的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!