Report this

What is the reason for this report?

Django - Gunicorn bind problem - Import error no module named django.conf

Posted on February 21, 2018

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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I have the same issue. Some answer?

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:


1. Verify the Virtual Environment

Ensure that the virtual environment where Django is installed is correctly activated.

  • Check if the virtual environment is active:
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

2. Avoid Using gunicorn_django

The 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.


3. Check Your Project’s wsgi.py File

Ensure 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()

4. Confirm Python Path

Gunicorn may be using the wrong Python interpreter, leading to the ImportError.

  • Check which Python Gunicorn is using:
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

`

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.