点突然使用错误的Python版本 [英] Pip suddenly using wrong version of Python

查看:94
本文介绍了点突然使用错误的Python版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在os x上pip出现奇怪的问题.

Having a weird problem with pip on os x.

据我所记得(并且快速浏览了我的.bash_history似乎可以确认),我最近没有对配置进行任何更改. las,pip命令似乎突然使用了不同于以前的python版本.到目前为止,我一直在使用命令pip管理我的python2库,并使用pip3命令通过python3库进行管理.突然,任何运行pip安装的尝试都会失败,并出现诸如打印语句周围缺少括号的错误.

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).

请注意,更新点数:

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.

这篇关于点突然使用错误的Python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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