Title: ModuleNotFoundError: No module named '*.apps'
Tags: python;django;wsgi;pythonanywhere;whitenoise
Question: I can`t run my django project on PythonAnywhere, because I have a problem with WSGI. I attach files with which there are problems. Does anyone know the solution to this problem?
Error log:
2018-08-14 12:50:34,868: Error running WSGI application
2018-08-14 12:50:34,868: ModuleNotFoundError: No module named 'test.apps'
2018-08-14 12:50:34,868:   File "/var/www/medhub_pythonanywhere_com_wsgi.py", line 11, in <module&gt;
2018-08-14 12:50:34,869:     application = DjangoWhiteNoise(get_wsgi_application())
2018-08-14 12:50:34,869:
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-08-14 12:50:34,869:     django.setup(set_prefix=False)
2018-08-14 12:50:34,869:
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
2018-08-14 12:50:34,869:     apps.populate(settings.INSTALLED_APPS)
2018-08-14 12:50:34,869:
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
2018-08-14 12:50:34,869:     app_config = AppConfig.create(entry)
2018-08-14 12:50:34,869:
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
2018-08-14 12:50:34,870:     mod = import_module(mod_path)
Django version: 1.10.8
WhiteNoise version: 3.0
settings.py path: /home/medhub/MedHub/MedHub/settings.py
settings.py file:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media/')
MEDIA_URL = 'static/media/'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '123'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'user.apps.UserConfig',
'database.apps.DatabaseConfig',
'content.apps.ContentConfig',
'test.apps.TestConfig',
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 = 'MedHub.urls'
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '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 = 'MedHub.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static',),)
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = '/'
test.apps file:
# -*- coding: utf-8 -*-
from django.apps import AppConfig
class TestConfig(AppConfig):
name = 'test'
verbose_name = 'Тесты'
WSGI file:
import os
import sys
path = '/home/medhub/MedHub'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'MedHub.settings'
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())
Comment: I mean, it tells you what it can't find, and then under your installed apps you have that value. That would be a good starting point for troubleshooting.

Comment: Try putting just test. That is how you register a normal Django app after creating. You don't need the module and class name in the installed apps setting.

Comment: It would also help to know your file structure -- you can get an ASCII-art version by starting bash, and running `cd /home/medhub/MedHub` and then `tree`.

Comment: @dfundako I do not understand why this happens. With the rest of the applications, everything is fine. Although they are registered identically. (On the local server everything works well)

Comment: @dfundako, thank you for your responses. I solved the problem. I tried to create an app like you said. And I got an error: 'test' conflicts with the name of an existing Python module and cannot be used as an app name.
I renamed the application and it all worked.


Here is another answer: 'test' conflicts with the name of an existing Python module and cannot be used as an app name. Renaming the application will help.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:08/14/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><django><wsgi><pythonanywhere><whitenoise>', 'Title': "ModuleNotFoundError: No module named '*.apps'", 'ViewCount': 2527, 'id': 51842485, 'user_AboutMe': None, 'user_AccountId': 14153205.0, 'user_DisplayName': 'Rubeus Hagrid', 'user_Reputation': 21.0, 'user_Views': 5.0, 'user_id': 10224663.0}}