Gunicorn Error: ModuleNotFoundError - No module named 'weatherapp.wsgi'
I'm having some trouble deploying my Django application on Heroku using Gunicorn, and I could really use some assistance.
Here's some background information about my project:
Project Name: weatherapp
Procfile
web: gunicorn weatherapp.wsgi:application --log-file -
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'weatherapp.settings')
application = get_wsgi_application()
Error Message
Traceback (most recent call last): File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker ... ModuleNotFoundError: No module named 'weatherapp.wsgi'
Relavent code in settings.py
WSGI_APPLICATION = 'content_aggregator.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
django_heroku.settings(locals())
MEDIA_URL = '/imgs/'
MEDIA_ROOT = BASE_DIR / 'imgs'
It seems like Gunicorn is unable to locate the weatherapp.wsgi module during the deployment process.
I've double-checked my project structure and everything seems to be in order. Could anyone please provide some guidance on what might be causing this issue and how I can resolve it?
Any help would be greatly appreciated. Thanks in advance!
Started the Gunicorn server with the command gunicorn weatherapp.wsgi:application --log-file -.
But no changes
The reason might be that unlike in dev mode your terminal does not sit within the folder of your project. I can't explain it well, but that procfile might try to start the app from within your home directory - but there is no weatherapp in it!
You could test this with creating a print_cwd.py:
import os
print("Current working directory:", os.getcwd())
and then within your procfile:
web: python /full/path/to/print_cwd.py
Give the full path here, otherwise it won't find the print_cwd.py file either.
To make your gunicorn run you can also just pass the full path! procfile
web: gunicorn /full/path/to/weatherapp.wsgi:application --log-file -