karlosss
karlosss

Reputation: 3155

uWSGI + Django: ImportError: No module named 'wsgi'

My project structure:

/srv/venv is the home of virtualenv (contains directories like bin or lib)

/srv/venv/webapp is the home of the Django application and contains the file wsgi.py

My .ini file:

[uwsgi]
plugins = python
chdir = /srv/venv/webapp
module = wsgi
home = /srv/venv/
master = true
processes = 10
socket = /tmp/srv.sock
chmod-socket = 666
vacuum = true
buffer-size = 32767
die-on-term = true

Upon startup, uWSGI says:

Wed Jul  4 10:58:40 2018 - chdir() to /srv/venv/webapp
Wed Jul  4 10:58:40 2018 - Set PythonHome to /srv/venv/
ImportError: No module named 'wsgi'

And every request ends up with:

Wed Jul  4 10:28:45 2018 - --- no python application found, check your startup logs for errors ---
[pid: 643|app: -1|req: -1/1] 192.168.33.1 () {42 vars in 653 bytes} [Wed Jul  4 10:28:45 2018] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

When I do cd /srv/venv/webapp, run python and type import wsgi, no errors happen.

Any ideas what might be wrong?

UPDATE: When I install and run uWSGI from the virtualenv (/srv/venv/bin/uwsgi), everything works fine. But why it is not working with system-wide uWSGI?

UPDATE2: I wrote a systemd service to run uWSGI at startup and it is not working again - same error. It starts working after I do systemctl restart uwsgi manually. Adding a 10 seconds delay did not solve it. I ran out of ideas.

Upvotes: 1

Views: 3765

Answers (1)

phil
phil

Reputation: 518

Assuming you wsgi.py looks something like this:

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
application = get_wsgi_application()

Your uwsgi.ini needs to be updated to:

module = wsgi:application

You can also add this in the uwsgi.ini to specify your virtual env:

virtualenv = /path/to/you/virtualenv

Upvotes: 3

Related Questions