python - Gunicorn, no module named 'myproject -


i'm installing built website on new server. i'm not original developer.

i've used gunicorn + nginx in past keep app alive (basically following this tutorial), having problems here.

i source venv/bin/activate, ./manage.py runserver 0.0.0.0:8000 works , running expected. shut down , run gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application, , following:

[2016-09-13 01:11:47 +0000] [15259] [info] starting gunicorn 19.6.0 [2016-09-13 01:11:47 +0000] [15259] [info] listening at: http://0.0.0.0:8000 (15259) [2016-09-13 01:11:47 +0000] [15259] [info] using worker: sync [2016-09-13 01:11:47 +0000] [15262] [info] booting worker pid: 15262 [2016-09-13 01:11:47 +0000] [15262] [error] exception in worker process traceback (most recent call last):   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker     worker.init_process()   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process     self.load_wsgi()   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi     self.wsgi = self.app.wsgi()   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi     self.callable = self.load()   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load     return self.load_wsgiapp()   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp     return util.import_app(self.app_uri)   file "/var/www/myproject/venv/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app     __import__(module) importerror: no module named 'myproject.wsgi' [2016-09-13 01:11:47 +0000] [15262] [info] worker exiting (pid: 15262) [2016-09-13 01:11:47 +0000] [15259] [info] shutting down: master [2016-09-13 01:11:47 +0000] [15259] [info] reason: worker failed boot. 

i believe structure of whole application. before, i've built apps basic structure of:

myproject ├── manage.py ├── myproject │   ├── urls.py │   ├── views.py │   ├── component1 │   │   ├── urls.py │   │   └── views.py │   ├── component2 │   │   ├── urls.py │   │   └── views.py ├── venv │   ├── bin │   └── ... 

this one, instead, has structure like:

myproject ├── apps │   ├── blog │   │   ├── urls.py │   │   ├── views.py │   │     └── ... │   ├── catalogue │   │   ├── urls.py │   │   ├── views.py │   │     └── ... │   ├── checkout │   │   ├── urls.py │   │   ├── views.py │   │     └── ... │   ├── core │   │   ├── urls.py │   │   ├── views.py │   │     └── ... │   ├── customer │   ├── dashboard │   └──  __init__.py ├── __init__.py ├── manage.py ├── project_static │   ├── assets │   ├── bower_components │   └── js ├── public │   ├── emails │   ├── media │   └── static ├── settings │   ├── base.py │   ├── dev.py │   ├── __init__.py │   ├── local.py │   └── production.py ├── templates │   ├── base.html │   ├── basket │   ├── blog │   └── .... ├── urls.py ├── venv │   ├── bin │   ├── include │   ├── lib │   ├── pip-selfcheck.json │   └── share └── wsgi.py 

so, there's no 'main' module running show, expect gunicorn looking for.

any thoughts?

wsgi.py:

import os  django.core.wsgi import get_wsgi_application  os.environ.setdefault("django_settings_module", "settings")  application = get_wsgi_application() 

your error message

importerror: no module named 'myproject.wsgi' 

you ran app with

gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application 

and wsgi.py has line

os.environ.setdefault("django_settings_module", "settings") 

this disconnect. in order recognize project myproject.wsgi parent directory have on python path... running

cd .. && gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application 

would eliminate error. however, different error because wsgi.py file refers settings instead of myproject.settings. implies app intended run root directory instead of 1 directory up. can figure out sure looking @ code- if uses absolute imports, from myproject.app import ... or from app import .... if guess correct, correct commmand is

gunicorn --bind 0.0.0.0:8000 wsgi:application 

if app use myproject in of paths, you'll have modify pythonpath run properly...

pythonpath=`pwd`/.. gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -