Question

I'm running a Django app that I used to deploy to Heroku with Gunicorn without a hitch. By that I mean that I could run

foreman start

on my localhost and be able to understand whether the application would work in the production environment. I recently made the decision to move all of our project's applications into a subfolder named 'applications'. This meant editing my DJANGO_SETTINGS_MODULE environment variable among other files. After doing this, I experimented with foreman and gunicorn until I got the local server up and running. At this point I deployed to production. Needless to say, there was an error:

Running `gunicorn --workers=4 applications.rocketlistings.wsgi -b 0.0.0.0: -k gevent` attached to terminal... up, run.8052
Traceback (most recent call last):
  File "/app/.heroku/python/bin/gunicorn", line 9, in <module>
    load_entry_point('gunicorn==0.17.2', 'console_scripts', 'gunicorn')()
  File "/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 343, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 2307, in load_entry_point
    return ep.load()
  File "/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 2013, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
ImportError: No module named app.wsgiapp

I'm not sure what I'm doing wrong, and it's very difficult to debug the situation given the obscure remote setup heroku runs. Other threads discussing this error suggest that this is a path problem. This sounds very plausible, but I can't think of what could be wrong with the path, given that I have an init.py file in my applications folder, and everything works locally.

Here is my production path/pythonpath anyway:

Running `echo $PATH` attached to terminal... up, run.2583
/app/.heroku/python/bin:/usr/local/bin:/usr/bin:/bin

Running `echo $PYTHONPATH` attached to terminal... up, run.8026
/app/

Thanks in advance!

Was it helpful?

Solution

Sometimes, this occurs when Gunicorn finds another module called 'app' in the PYTHONPATH. Setting PYTHONPATH to a fake value resolves the issue:

$ heroku config:set PYTHONPATH=fakepath

https://github.com/heroku/heroku-buildpack-python/wiki/Troubleshooting#no-module-named-appwsgiapp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top