1
Vote

Gevent Fails to Import in PTVS 2.1 Beta

description

VS 2010 with PTVS 2.1 Beta and Python 2.7.

I get an "ImportError: No module named greenlet" when I execute my Flask Web Project. The error is related to the "import greenlet" statement in gevent's hub.py. I've installed and reinstalled both gevent and greenlet in several locations: Python27\Lib\site-packages, Python27\Lib, and in the Python Environments "env\Lib" folder associated with the project. Moving greenlet.py out of gevent folder resolves the issue in hub.py, but then the error occurs in greenlet.py's "from gevent.hub import greenlet..."

Notably, I do not have any issues with the same import statement ("import gevent") in IDLE.

Any help or suggestions are greatly appreciated.

comments

Zooba wrote May 16 at 6:41 PM

I haven't checked out gevent/greenlet's install procedure. Do you know if it modifies your global PYTHONPATH variable? What does its folder structure look like when you install it?

aaapurdy wrote May 19 at 1:54 PM

Zooba -

gevent and greenlet are both available via easy_install, but they can be installed manually also. I'm new to both these modules, but the only apparent dependency between gevent and greenlet is greenlet.py. I do not think either install modified the PYTHONPATH. I tried manually appending the path to gevent's folder, but this also did not resolve the problem in VS 2010 (still works in IDLE).

The folder structure is identical to what's on GitHub (https://github.com/surfly/gevent) within my Python\Lib\gevent path.

aaapurdy wrote May 19 at 3:34 PM

Some additional information that may be helpful...

"import gevent" works in the Python Interactive window and also when using VS 2010 with a Python Application project. The issues seems to be isolated to the Flask Web Project. Perhaps related to the virtual environment?

Zooba wrote May 19 at 3:50 PM

Ah, you're using a virtual environment.

You will definitely need gevent installed into the virtual environment, unless you've manually created it to inherit packages from the global Python (this is disabled by default because it rather defeats the purpose).

In 2.1 Beta you should be able to right-click your virtual environment and open an Interactive window specifically for that (or maybe you need to go through the Environments List window, but I think beta has the context menu). If the import works from here and not when running, then Flask must be doing something strange.

Hopefully (because it's the easiest to fix), importing gevent in the virtual environment's interactive window will fail and give a helpful error message.

aaapurdy wrote May 19 at 5:11 PM

Zooba - thank you again for your help. This time I installed greenlet then gevent using PIP directly into the virtual environment. It is now running correctly.