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 "", line 1, in

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 :(

This is the content of 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']

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.

解决方案

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.

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐