配置Gunicorn与Django时出现No module named revamp.wsgi错误求助
Alright, let's get that Gunicorn service up and running. The error you're seeing happens because Gunicorn isn't looking in the right directory to find your Django project's WSGI module—even though the file exists, the working context is off.
Here's what to do:
Update your Gunicorn systemd config
Open your/etc/systemd/system/gunicorn.servicefile and adjust theWorkingDirectorypath. Right now it's set to/home/muiruri_samuel/webapp, but your Django project's root (where therevamppackage containingwsgi.pylives) is one level deeper. Update the config to:[Unit] Description=gunicorn daemon After=network.target [Service] User=muiruri_samuel Group=www-data WorkingDirectory=/home/muiruri_samuel/webapp/revamp ExecStart=/home/muiruri_samuel/webapp/djangoenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/muiruri_samuel/webapp/revamp/revamp.sock revamp.wsgi:application [Install] WantedBy=multi-user.targetReload systemd and restart Gunicorn
Systemd needs to pick up the config change, so run these commands:sudo systemctl daemon-reload sudo systemctl restart gunicornVerify the service status
Check if the service is now running properly:sudo systemctl status gunicorn
Why this works:
When Gunicorn starts, it uses the WorkingDirectory as its base path. Your revamp.wsgi module lives inside /home/muiruri_samuel/webapp/revamp/revamp/—so by setting the working directory to /home/muiruri_samuel/webapp/revamp, Gunicorn can properly locate the revamp Python package (which contains wsgi.py) when it tries to import revamp.wsgi.
Quick double-check: Make sure the /home/muiruri_samuel/webapp/revamp/revamp directory has an __init__.py file (it should be there by default if you created the Django project with startproject). This file tells Python that the directory is a valid importable package.
内容的提问来源于stack exchange,提问作者Samuel Muiruri

