ModuleNotFoundError: No module named "tip_administration_app"
I'm trying to set up a complete environment to run a Django application on ubuntu 22.04 with gunicorn and nginx. I use a droplet provided by Digital Ocean and i'm trying to follow this tutorial : https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04
Everything is going well until I have to link gunicorn to my wsgi.py file.
When i'm trying this command :
gunicorn --bind 0.0.0.0:8000 tip_administration_app.wsgi
I have this error :
[2022-12-20 14:08:25 +0000] [20676] [INFO] Starting gunicorn 20.1.0
[2022-12-20 14:08:25 +0000] [20676] [INFO] Listening at: http://0.0.0.0:8000 (20676)
[2022-12-20 14:08:25 +0000] [20676] [INFO] Using worker: sync
[2022-12-20 14:08:25 +0000] [20677] [INFO] Booting worker with pid: 20677
[2022-12-20 14:08:25 +0000] [20677] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/django/the-ideal-partner/myprojectenv/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tip_administration_app'
[2022-12-20 14:08:25 +0000] [20677] [INFO] Worker exiting (pid: 20677)
[2022-12-20 14:08:25 +0000] [20676] [INFO] Shutting down: Master
[2022-12-20 14:08:25 +0000] [20676] [INFO] Reason: Worker failed to boot.
Here is my project structure :
tip-project
-- myprojectenv
-- Procfile
-- requirements.txt
-- TIP_PROJECT
-- manage.py
-- authentication_app
-- __init__.py
-- forms.py
-- models.py
-- views.py
-- templates
-- static
-- partnerinfos_app
-- __init__.py
-- forms.py
-- models.py
-- views.py
-- templates
-- static
-- tip_administration_app
-- __init__.py
-- asgi.py
-- settings.py
-- urls.py
-- wsgi.py
My settings.py contains :
import os
from pathlib import Path
import sys
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secretkeystackoverflow'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['142.93.139.198','localhost', 'test.theidealpartner.fr']
AUTH_USER_MODEL = 'authentication_app.User'
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authentication_app',
'partnerinfos_events_app',
'tip_administration_app',
'pytest',
'coverage',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'tip_administration_app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR.joinpath('templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'tip_administration_app.wsgi.application'
# Database
DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME':'theidealpartnerdb',
'USER':'django_user',
'PASSWORD':'PAssworddbstackoverflow',
'HOST':'127.0.0.1',
'PORT':'3306',
'OPTIONS':{
}
}
}
# Password validation
AUTH_PASSWORD_VALIDATORS = [
# See validators in tip_administration_app.validators
]
# Internationalization
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / "authentication_app/static/authentication_app",
BASE_DIR / "partnerinfos_events_app/static/partnerinfos_events_app",
]
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTH_USER_MODEL='authentication_app.User'
LOGIN_URL = '/'
# EMAIL settings. To change in production
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
EMAIL_FILE_PATH = BASE_DIR /"authentication_app/sent_emails"
FILE_UPLOAD_TEMP_DIR = "/tmp"
# Date format settings. See "Datefield()" in models.py
DATE_INPUT_FORMATS = ('%Y-%m-%d')
# needed for pytest Stack-Overflow : https://stackoverflow.com/questions/48163641/django-core-exceptions-a>
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
Here is wsgi.py :
"""
WSGI config for TIP project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tip_administration_app.settings')
application = get_wsgi_application()
I already tried all subjects on this topic on stack overflow but none of them helped me...
Any advices would be appreciated.