如何在Python virtualenv中安装gevent?

时间:2015-09-22 07:00:52

标签: python linux ubuntu virtualenv

我尝试在我的Ubuntu 14.04服务器上使用virtualenv,但我似乎无法安装gevent。我首先激活virtualenv,我使用pip安装gevent

$ source venv/bin/activate
(venv)immoh@vgmt:~/immod$ sudo pip install gevent
The directory '/home/immoh/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/immoh/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied (use --upgrade to upgrade): gevent in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): greenlet>=0.4.7 in /usr/local/lib/python2.7/dist-packages (from gevent)

在此之后,我尝试从python命令行使用它:

(venv)immoh@vgmt:~/immod$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named gevent
>>>

这似乎不起作用,所以我尝试使用sudo's -H flag安装它,如上面的消息所示,但在此之后,我无法导入gevent

(venv)immoh@vgmt:~/immod$ sudo -H pip install gevent
Requirement already satisfied (use --upgrade to upgrade): gevent in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): greenlet>=0.4.7 in /usr/local/lib/python2.7/dist-packages (from gevent)
(venv)immoh@vgmt:~/immoh$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named gevent

有人知道我在这里做错了什么以及如何解决这个问题?欢迎所有提示!

1 个答案:

答案 0 :(得分:3)

问题的根源在于您不应该使用sudo。一旦您在virtualenv中工作,只需在没有pip的情况下运行sudo,您就不会遇到任何问题。

顺便说一下,我建议创建一个新的virtualenv来试试这个,以避免以前尝试产生的任何问题。