Python看不到pip安装的模块

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

(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

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

这是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,则可以看到该包:

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

为什么会发生这种情况,我该怎么办?

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

解决方法:

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

Python packages not installing in virtualenv using pip

上一篇:python-Windows上的Virtualenv和Komodo IDE 6


下一篇:python虚拟环境配置