gunicorn import error on heroku gunicorn import error on heroku flask flask

gunicorn import error on heroku


In my case, I got this error by having a gunicorn.py file in my top level folder. This clashed with the installed gunicorn library on Heroku.

So my run command that caused the problem was:

gunicorn -c gunicorn.py myapp:main

Raising the following error:

Traceback (most recent call last):  File "/app/.heroku/python/bin/gunicorn", line 9, in <module>    load_entry_point('gunicorn==18.0', 'console_scripts', 'gunicorn')()  File "/app/.heroku/python/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point    return get_distribution(dist).load_entry_point(group, name)  File "/app/.heroku/python/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point    return ep.load()  File "/app/.heroku/python/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load    entry = __import__(self.module_name, globals(),globals(), ['__name__'])ImportError: No module named app.wsgiapp

Whereas after a mv gunicorn.py gunicorn_config.py it worked fine with:

gunicorn -c gunicorn_config.py myapp:main


I ran into this problem when upgrading Ubuntu to 14.04 LTS.

For some reason, gunicorn failed to pick up the correct python path to resolve the wsgi module.

I resolved this, for now, by declaring the python path explicitly to gunicorn via the --pythonpath parameter (documented here).

For example:

gunicorn --pythonpath /path/to/containing/directory "app.wsgi_app:wsgi_app"


I finally figured this one out.

It's basically just a PATH problem. If you import certain modules (like os and sys) in the wrong order depending on your setup, you will cause Gunicorn to look in the wrong package for the app.wsgiapp module. (not to be confused with the app.wsgi_app function in Flask)

The correct import order will vary depending on your setup, but the rule of thumb based on what I was able to get working was to just make sure that your sys module is imported before your os module.

Beyond that, assuming the rest of the config is normal (as above) you shouldn't have any issues.

Note: THIS IS ONLY A PROBLEM ON HEROKU with Gunicorn. It has something to do with how their PYTHONPATH and module search path is set up. I don't know why exactly, but this is only necessary for the production environment, local setups will work fine regardless of the module import order.