简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM