Your error message is
ImportError: No module named 'myproject.wsgi'
You ran the app with
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
And wsgi.py has the line
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
This is the disconnect. In order to recognize the project as myproject.wsgi
the parent directory would have to be on the python path… running
cd .. && gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
Would eliminate that error. However, you would then get a different error because the wsgi.py file refers to settings
instead of myproject.settings
. This implies that the app was intended to be run from the root directory instead of one directory up. You can figure this out for sure by looking at the code- if it uses absolute imports, do they usually say from myproject.app import ...
or from app import ...
. If that guess is correct, your correct commmand is
gunicorn --bind 0.0.0.0:8000 wsgi:application
If the app does use myproject
in all of the paths, you’ll have to modify your PYTHONPATH to run it properly…
PYTHONPATH=`pwd`/.. gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application