ImportError: No module named eventlet

the_unknown_spirit picture the_unknown_spirit · Feb 5, 2016 · Viewed 15.7k times · Source

I have installed eventlet library in python using : pip install eventlet. But when I tried to import eventlet this error occured:

$python 
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import eventlet
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named eventlet

I tried to install it again but I got this :

$pip install eventlet
Requirement already satisfied (use --upgrade to upgrade): eventlet in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/eventlet-0.18.1-py3.5.egg
Requirement already satisfied (use --upgrade to upgrade): greenlet>=0.3 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/greenlet-0.4.9-py3.5-macosx-10.6-intel.egg (from eventlet)

How to rectify this error?

P.S : I am using Python 2.7

Answer

temoto picture temoto · Feb 7, 2016

This question is not specific to Eventlet, it's just about managing multiple versions of Python on OSX.

Your pip command installed eventlet into /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5, see version.

It means you actually have two Python versions installed: 2.7 and 3.5 and pip works with 3.5.

Your options:

  • (recommended) use separate virtualenv [1] for every project, explicitly specify python version when creating virtualenv using virtualenv --python=python2.7 /path/to/new/venv
  • run python3 and use eventlet in latest Python
  • run pip2 install eventlet
  • symlink pip to pip2 ln -snf $(which pip2) $(which pip)

[1] http://docs.python-guide.org/en/latest/dev/virtualenvs/