kramer65
kramer65

Reputation: 53873

How to install gevent in a Python virtualenv?

I'm trying to use virtualenv on my Ubuntu 14.04 server, but I can't seem to install gevent. I first activate virtualenv, afther which I install gevent using pip:

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

After this I try to use it from the python command line:

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

That didn't seem to work, so I tried installing it using the sudo's -H flag as suggested by the message above, but after that again, I can't import 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

Does anybody know what I'm doing wrong here and how I can solve this? All tips are welcome!

Upvotes: 1

Views: 2490

Answers (1)

taleinat
taleinat

Reputation: 8711

The source of the problem is that you are using sudo when you should not be. Once you're working in a virtualenv, just run pip without sudo and you should have none of these issues.

By the way, I recommend creating a new virtualenv in which to try this, to avoid any problems created by your previous attempts.

Upvotes: 3

Related Questions