本文介绍了Python看不到pip安装的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用全新的Python virtualenv.我刚刚使用pip安装了httplib2,但是Python无法看到它.

I'm working in a brand new Python virtualenv. I've just installed httplib2 using pip, but Python cannot see it.

(venv)$ sudo pip install httplib2
Requirement already satisfied (use --upgrade to upgrade): httplib2 in
/usr/local/lib/python2.7/dist-packages
Cleaning up...
(venv)$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib2
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 ImportError: No module named httplib2

从我的阅读看来,这可能是路径问题,但我不知道为什么会发生,或如何解决它:(

From my reading, it sounds like this is probably a path problem, but I don't know why it is happening, or how to fix it :(

这是sys.path的内容:

>>> pprint(sys.path)
['',
 '/var/apps/ttex/venv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
 '/var/apps/ttex/venv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
 '/var/apps/ttex/venv/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
 '/var/apps/ttex/venv/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
 '/var/apps/ttex/venv/lib/python2.7',
 '/var/apps/ttex/venv/lib/python2.7/plat-linux2',
 '/var/apps/ttex/venv/lib/python2.7/lib-tk',
 '/var/apps/ttex/venv/lib/python2.7/lib-old',
 '/var/apps/ttex/venv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/var/apps/ttex/venv/local/lib/python2.7/site-packages',
 '/var/apps/ttex/venv/lib/python2.7/site-packages']

但是奇怪的是,如果我运行Python 2.7,则可以看到该软件包:

Oddly though, if I run Python 2.7, I can see the package:

(venv)$ python2.7
>>> import httplib2
>>>

为什么会这样,我该怎么办?

Why is this happening and what can I do about it?

很抱歉,如果重复的话,围绕该主题有很多问题,但是似乎没有一个给出明确的答案.

Sorry if this is a duplicate, there are lots of questions around this topic, but none seem to give a simple definitive answer.

推荐答案

在全新的virtualenv中不使用sudo尝试一下. Pip认为您想在全局范围内安装它,所以要安装到/usr,而不是沙箱中.

Try it without the sudo in a fresh virtualenv. Pip thinks that you want to install it in global scope, so to /usr, not in your sandbox.

Python软件包未使用pip安装在virtualenv中

这篇关于Python看不到pip安装的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:53