user1757703
user1757703

Reputation: 3015

Django Gunicorn: Unable to find application

I started with a fresh install of django into a Python 3.4 virtualenv. I then tried to start gunicorn following a tutorial to test on the first ever run and it fails. I have a fully configured development server in which gunicorn fails to run showing me the same error that there is no module named <django project name>.wsgi.

(test_projectprodenv)djangouser@ff:~$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001
Exception in worker process:
Traceback (most recent call last):
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/arbiter.py", line 502, in spawn_worker
    worker.init_process()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/workers/base.py", line 114, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/base.py", line 66, in wsgi
    self.callable = self.load()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/util.py", line 356, in import_app
    __import__(module)
ImportError: No module named 'test_project.wsgi'

The only reason I started a new server to test this new Django project is in the hopes that gunicorn will work thinking I might have misconfigured something on my old dev server. Keep in mind that this is completely fresh. I have touched nothing in the Django project folder or settings.py except for configuring the database.

EDIT: Added file structure.

(test_projectprodenv)djangouser@ff:~$ ls
test_project  test_projectprodenv  

(test_projectprodenv)djangouser@ff:~/test_project$ tree
.
├── test_project
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-34.pyc
│   │   ├── settings.cpython-34.pyc
│   │   ├── urls.cpython-34.pyc
│   │   └── wsgi.cpython-34.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

2 directories, 9 files

The gunicorn command is being executed from test_project folder.

(test_projectprodenv)djangouser@ff:~$ which gunicorn
/home/djangouser/test_projectprodenv/bin/gunicorn

Upvotes: 3

Views: 8778

Answers (1)

famousgarkin
famousgarkin

Reputation: 14116

If your application is not installed in the Python environment along with Gunicorn, you have to add it on the Python path, so that Gunicorn can see it, either by running from where the package is located or by specifying that location via the --pythonpath STRING command line option.

So either start the server from ~/test_project:

~/test_project$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001

or with --pythonpath option from your home directory:

~$ gunicorn test_project.wsgi:application --pythonpath test_project --bind 162.243.195.141:8001

Upvotes: 15

Related Questions