Problem description:
When migrating from runserver to Gunicorn and running command “gunicorn -c gunicorn.conf.py cloudmonitor.wsgi.application”, receive error ModuleNotFoundError: No module named ‘cloudmonitor’
I reviewed the link https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/gunicorn/ but I am not understanding the error when running the command.
I configured a config file for Gunicorn and put it in the same directory as manage.py.
Environment information:
Django 5.1.0
Gunicorn 23.0.0
Nginx Reverse Proxy
RHEL 8 Virtual Machine
[user@server01 cloudmonitor]$ ls -la
total 48
drwxr-xr-x 3 user Users 4096 Aug 14 16:25 .
drwxr-xr-x 12 user Users 4096 Aug 14 16:08 …
-rw-r–r-- 1 user Users 417 Jul 25 02:49 asgi.py
-rw-r–r-- 1 user Users 1079 Jul 26 23:41 db_test.py
-rw-r–r-- 1 user Users 4201 Aug 14 13:45 gunicorn.conf.py
-rw-r–r-- 1 user Users 0 Jul 25 02:49 init.py
drwxr-xr-x 2 user Users 4096 Aug 14 16:17 pycache
-rw-r–r-- 1 user Users 6868 Aug 14 16:09 settings.py
-rw-r–r-- 1 user Users 180 Aug 14 03:25 ssl_test.py
-rw-r–r-- 1 user Users 1379 Aug 8 10:49 urls.py
-rw-r–r-- 1 user Users 414 Aug 14 16:25 wsgi.py
asgi.py
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘cloudmonitor.settings’)
application = get_asgi_application()
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘cloudmonitor.settings’)
application = get_wsgi_application()
Settings.py
import os
import environs
from pathlib import Path
from environs import Env
env = Env()
env.read_env()
BASE_DIR = Path(file).resolve().parent.parent
SECRET_KEY = env.str(“SECRET_KEY”)
DEBUG = env.bool(“DEBUG”, default=False)
ALLOWED_HOSTS = [‘192.168.46.69’, ‘localhost’, ‘127.0.0.1’]
Application definition
INSTALLED_APPS = [
‘authentication’,
‘dashboard’,
‘rest_framework’,
‘django_filters’,
‘corsheaders’,
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
]
CORS_ORIGIN_ALLOW_ALL = True
MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘corsheaders.middleware.CorsMiddleware’,
‘django.middleware.common.CommonMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’,
‘django.middleware.clickjacking.XFrameOptionsMiddleware’,
]
ROOT_URLCONF = ‘cloudmonitor.urls’
WSGI_APPLICATION = ‘cloudmonitor.wsgi.application’
Other lines in settings.py omitted.