Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gunicorn 'ImportError: No module named app.wsgiapp' on heroku

I cannot run gunicorn on heroku with simple flask app.
The application is really simple. This is app.py:

app = Flask(__name__)

@app.route("/")
def say_hello(url):
    return "Hello"


if __name__ == "__main__":
    port = int(os.environ.get('PORT', 8888))
    app.run(host='0.0.0.0',port=port)

The app works fine through flask test server on heroku, but when I switch to use gunicorn, it crashes with:

ImportError: No module named app.wsgiapp

My requirements.txt:

Flask==0.8
gevent==0.13.7
gunicorn==0.13.2

I've tried different versions of gunicorn from 0.13.7 to 0.14.6 with no success.

Procfile:

web: gunicorn app:app -w 4 -b 0.0.0.0:$PORT

Running this command:

heroku logs

gives this:

←[33m2012-08-09T21:08:02+00:00 app[web.1]:←[0m ImportError: No module named app.
wsgiapp ←[33m2012-08-09T21:08:02+00:00 app[web.1]:←[0m     entry = __import__(self.modul
e_name, globals(),globals(), ['__name__'])

Any help please?

like image 631
Joseph Avatar asked Aug 09 '12 21:08

Joseph


1 Answers

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
like image 136
user835325 Avatar answered Oct 19 '22 10:10

user835325