Search code examples
pythondjangoweb-applicationsplotly-dashdjango-settings

ModuleNotFoundError: No module named 'django_plotly_dash'


I am creating a web application using django_plotly_dash, a module combining Django, Plotly, and Dash into one package. I am running into an issue where when I try to work with the manage.py file to run commands, I get the error ModuleNotFoundError: No module named 'django_plotly_dash'

From research and the traceback, it seems to problem lies either in my settings.py file specifically with static files/bootstrapping or in my directory structure. Does anybody with more experience with this see any issues in my structures or settings.py that are causing this error

Here is the Traceback message:

Traceback (most recent call last):
  File "C:\Users\mvela\Documents\Internships\Contracts\Greene\July Contract\web_app\report_app\manage.py", line 22, in <module>
    main()
  File "C:\Users\mvela\Documents\Internships\Contracts\Greene\July Contract\web_app\report_app\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\mvela\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line        
    utility.execute()
  File "C:\Users\mvela\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 395, in execute
    django.setup()
  File "C:\Users\mvela\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\__init__.py", line 
24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\mvela\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\apps\registry.py", 
line 91, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\mvela\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\apps\config.py", line 212, in create
    mod = import_module(mod_path)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, 
level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
228, in _call_with_frames_removed            228, in _call_with_frames_r
  File "<frozen importlib._bootstrap>", line 
1030, in _gcd_import                         1030, in _gcd_import       
  File "<frozen importlib._bootstrap>", line             nd_and_load    
1007, in _find_and_load                      1007, in _fid_and_load_unlo
  File "<frozen importlib._bootstrap>", line 
984, in _find_and_load_unlocked              984, in _fin
ModuleNotFoundError: No module named 'django_plotly_dash'      

Here is my directory:

Directory from VS Code Explorer

the first level report_app is the main project while the second level home and report_app are django apps within the main project.

and here is my settings.py:

"""
Django settings for report_app project.

Generated by 'django-admin startproject' using Django 3.2.4.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-8do=a0m+%$#t^57z4$e6$^13t=5ys1dk29j@21$f_+9=%83d2v'

# 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',
    'django_plotly_dash.apps.DjangoPlotlyDashConfig',
    'home.apps.HomeConfig',
    'channels',
    'channels_redis'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',

      'whitenoise.middleware.WhiteNoiseMiddleware',

      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',

      'django_plotly_dash.middleware.BaseMiddleware',
      'django_plotly_dash.middleware.ExternalRedirectionMiddleware',

      'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'report_app.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'report_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

CRISPY_TEMPLATE_PACK = 'bootstrap4'

ASGI_APPLICATION = 'report_app.routing.application'
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis,core,RedisChannelLayer',
        'CONFIG': {
            'hosts': [('127.0.0.1', 6379)]
        }
    }
}

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',

    'django_plotly_dash.finders.DashAssetFinder',
    'django_plotly_dash.finders.DashComponentFinder',
    'django_plotly_dash.finders.DashAppDirectoryFinder'
]

PLOTLY_COMPONENTS = [
    'dash_core_components',
    'dash_html_components',
    'dash_renderer',
    'dpd_components',
    'dash_bootstrap_components'
]


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATICFILES_LOCATION = 'static'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_FILES_DIR = [
    os.path.join(BASE_DIR, 'report_app/static')
]

X_FRAME_OPTIONS = 'SAMEORIGIN'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

If it helps, I was following the following tutorial on using this package:

https://www.youtube.com/watch?v=psvU4zwO3Ao

Please let me know if any further info will help with solving this.


Solution

  • After tinkering, it seems like @yagus was right. I created a new virtualenv and redid the pip installations and now it works. I must have set it up wrong the first time. Thanks for the help @yagus