I am going through the How To Install and Configure Django with Postgres, Nginx, and Gunicorn tutorial and I got stuck in the ninth step.
When I try to execute the command gunicorn_django bind… I get an error that says Import error: no module named django.conf that is coming from the …/gunicorn/app/django_wsgi.py.
The virtualenv is activated, I am logged in as root and I also tried to run that command with sudo. Still no success…
Any ideas?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
The error ImportError: No module named django.conf when running gunicorn_django suggests that Gunicorn cannot find your Django installation or project. Here are the most likely causes and steps to resolve the issue:
Ensure that the virtual environment where Django is installed is correctly activated.
echo $VIRTUAL_ENV
This should output the path to your virtual environment. If it’s empty, activate the virtual environment:
source /path/to/your/venv/bin/activate
Confirm Django is installed in the virtual environment:
pip list | grep Django
If Django is not listed, install it:
pip install django
gunicorn_djangoThe gunicorn_django command has been deprecated and removed in newer Gunicorn versions. Instead, you should use the following command:
gunicorn your_project_name.wsgi:application --bind 0.0.0.0:8000
Replace your_project_name with the name of your Django project.
wsgi.py FileEnsure the wsgi.py file exists and is configured correctly. It should be located in the root of your project folder (e.g., your_project_name/wsgi.py).
A typical wsgi.py file looks like this:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project_name.settings')
application = get_wsgi_application()
Gunicorn may be using the wrong Python interpreter, leading to the ImportError.
which gunicorn
Ensure it's the one inside your virtual environment (e.g., `/path/to/venv/bin/gunicorn`).
If not, specify the Python interpreter explicitly when running Gunicorn:
/path/to/venv/bin/gunicorn your_project_name.wsgi:application --bind 0.0.0.0:8000
`
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.