Search code examples
python-2.7gevent

no module named gevent even though it is installed


OS : Ubuntu 16.04 Python 2.7

pip list | grep gev
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
gevent (1.3a2)

Just to make sure, I checked:

  pip install --upgrade gevent
Requirement already up-to-date: gevent in /home/user/.local/lib/python2.7/site-packages
Requirement already up-to-date: greenlet>=0.4.13; platform_python_implementation == "CPython" in /home/user/.local/lib/python2.7/site-packages (from gevent)

However when I actually run my python program it bails out with an error:

 import gevent
ImportError: No module named gevent

Please advise.

Stuff I already tried:

pip --version
pip 9.0.1 from /home/user/.local/lib/python2.7/site-packages (python 2.7)


python -m pip install --user gevent
Requirement already satisfied: gevent in /home/user/.local/lib/python2.7/site-packages
Requirement already satisfied: greenlet>=0.4.13; platform_python_implementation == "CPython" in /home/user/.local/lib/python2.7/site-packages (from gevent)

which -a python
/usr/bin/python
/usr/bin/python

along with things mentioned here: https://github.com/PokeAlarm/PokeAlarm/issues/22

I also tried uninstalling the pip installation and doing apt-get :

sudo apt-get install python-gevent python-gevent-websocket

mentioned here: https://askubuntu.com/questions/836029/importerror-no-module-named-gevent/1013457#1013457


Solution

  • Working in a Python virtual environment in Ubuntu 16.04 I got the following results:

    $ python -m pip install gevent 
    Requirement already satisfied: gevent in ./lib/python2.7/site-packages  
    Requirement already satisfied: greenlet>=0.4.10 in ./lib/python2.7/site-packages (from gevent)

    import gevent worked successfully in my Python virtual environment, but it did not work outside of my Python virtual environment until I ran the following command:

    sudo apt install python-gevent # also works in all currently supported versions of Ubuntu 
    

    Description: gevent is a coroutine-based Python networking library. gevent uses greenlet to provide a high-level synchronous API on top of libevent event loop.

    You can also install python3-gevent for Python 3.x in all currently supported versions of Ubuntu by running the following command:

    sudo apt install python3-gevent