Gunicorn+Django+Heroku. Python Path Issue

与世无争的帅哥 提交于 2019-12-11 02:16:52

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/15604475/gunicorndjangoheroku-python-path-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!