ModuleNotFoundError: No module named 'django.contrib.wagtail'

1.3k Views Asked by At

Recent Error Log (python manage.py runserver):

Django version 3.2.6, using settings 'empoweru.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\GA\venv\lib\site-packages\django\core\servers\basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "D:\GA\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "D:\GA\fitgirl-inc\empoweru\wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "D:\GA\venv\lib\site-packages\django\core\wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "D:\GA\venv\lib\site-packages\django\core\handlers\wsgi.py", line 127, in __init__
    self.load_middleware()
  File "D:\GA\venv\lib\site-packages\django\core\handlers\base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "D:\GA\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'wagtail.core.middleware'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "D:\GA\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\GA\venv\lib\site-packages\django\core\management\commands\runserver.py", line 138, in inner_run
    handler = self.get_handler(*args, **options)
  File "D:\GA\venv\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "D:\GA\venv\lib\site-packages\django\core\management\commands\runserver.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "D:\GA\venv\lib\site-packages\django\core\servers\basehttp.py", line 50, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'empoweru.wsgi.application' could not be loaded; Error importing module.

=================================================================

Updated:

I dropped the database and created a new one in pgAdmin and executed python manage.py makemigrations and python manage.py migrate - Both worked.

When I ran python manage.py runserver, I get the following error:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\GA\venv\lib\site-packages\django\core\servers\basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "D:\GA\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "D:\GA\fitgirl-inc\empoweru\wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "D:\GA\venv\lib\site-packages\django\core\wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "D:\GA\venv\lib\site-packages\django\core\handlers\wsgi.py", line 127, in __init__
    self.load_middleware()
  File "D:\GA\venv\lib\site-packages\django\core\handlers\base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "D:\GA\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.contrib.wagtail'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "D:\GA\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\GA\venv\lib\site-packages\django\core\management\commands\runserver.py", line 138, in inner_run
    handler = self.get_handler(*args, **options)
  File "D:\GA\venv\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "D:\GA\venv\lib\site-packages\django\core\management\commands\runserver.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "D:\GA\venv\lib\site-packages\django\core\servers\basehttp.py", line 50, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'empoweru.wsgi.application' could not be loaded; Error importing module.

================================================================== We are working on a Django project and wanting to upgrade the packages to the latest version. To begin with, we tried installing all the packages related to the project as mentioned in the requirements.txt. While installing the packages mentioned in the requirements.txt file, some of packages required upgrades. So, we upgraded them accordingly, please find the latest packages installed in the project under requirements_new.txt (File generated using pip freeze > requirements_new.txt). We were able to successfully install all the packages. However, when we execute python manage.py makemigrations, we are getting the below error:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "D:\GA\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "D:\GA\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    django.setup()
  File "D:\GA\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\GA\venv\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "D:\GA\venv\lib\site-packages\django\apps\config.py", line 224, in create
    import_module(entry)
  File "C:\Users\sweth\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.contrib.wagtail'

Please find below the packages in requirements_new.txt

anyascii==0.2.0
asgiref==3.4.1
atomicwrites==1.3.0
backports.zoneinfo==0.2.1
beautifulsoup4==4.9.3
bleach==3.1.4
boto3==1.11.10
botocore==1.14.10
certifi==2021.5.30
cffi==1.13.2
chardet==3.0.4
charset-normalizer==2.0.4
cssselect2==0.2.2
defusedxml==0.6.0
dj-database-url==0.5.0
Django==3.2.6
django-appconf==1.0.3
django-avatar==5.0.0
django-classy-tags==1.0.0
django-cogwheels==0.3
django-contrib-comments==1.9.2
django-cors-headers==3.8.0
django-crispy-forms==1.8.1
django-filter==2.4.0
django-formtools==2.2
django-imagekit==4.0.1
django-modelcluster==5.1
django-sekizai==1.1.0
django-social-share==1.3.2
django-storages==1.8
django-taggit==1.5.1
django-treebeard==4.5.1
django-webpack-loader==0.6.0
django-widget-tweaks==1.4.5
djangocms-admin-style==1.2.8
djangorestframework==3.12.4
docutils==0.15.2
draftjs-exporter==2.1.7
et-xmlfile==1.1.0
filebrowser-safe==0.5.0
future==0.18.2
grappelli-safe==0.5.2
gunicorn==19.9.0
html5lib==1.1
idna==3.2
importlib-resources==5.2.2
jmespath==0.9.4
l18n==2020.6.1
Mezzanine==4.3.1
numpy==1.19.5
oauthlib==3.1.0
openpyxl==3.0.7
pandas==0.25.3
pilkit==2.0
Pillow==8.3.1
psycopg2-binary==2.8.4
pycparser==2.19
PyJWT==2.1.0
Pyphen==0.9.5
python-dateutil==2.8.1
python-decouple==3.3
python3-openid==3.1.0
pytz==2021.1
requests==2.26.0
requests-oauthlib==1.3.0
rjsmin==1.1.0
s3transfer==0.3.2
semantic-version==2.8.5
six==1.16.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
soupsieve==2.2.1
sqlparse==0.4.1
tablib==3.0.0
telepath==0.2
tinycss2==0.6.1
toml==0.10.2
typing-extensions==3.10.0.0
tzdata==2021.1
tzlocal==2.0.0
Unidecode==1.1.1
urllib3==1.26.6
wagtail==2.14.1
wagtail-gallery==0.1.1
wagtailmenus==3.0.2
webencodings==0.5.1
whitenoise==5.0.1
Willow==1.4
xlrd==2.0.1
XlsxWriter==1.4.5
xlwt==1.3.0
zipp==3.5.0

Please find below the packages in requirements.txt

asgiref==3.2.3
atomicwrites==1.3.0
beautifulsoup4==4.6.0
bleach==3.1.4
boto3==1.11.10
botocore==1.14.10
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
cssselect2==0.2.2
defusedxml==0.6.0
dj-database-url==0.5.0
Django==2.2.10
django-appconf==1.0.3
django-avatar==5.0.0
django-classy-tags==1.0.0
django-cogwheels==0.3
django-compressor==2.4
django-contrib-comments==1.9.2
django-cors-headers==3.2.1
django-crispy-forms==1.8.1
django-formtools==2.2
django-imagekit==4.0.1
django-modelcluster==5.0.1
django-sekizai==1.1.0
django-social-share==1.3.2
django-storages==1.8
django-taggit==1.2.0
django-treebeard==4.3.1
django-webpack-loader==0.6.0
django-widget-tweaks==1.4.5
djangocms-admin-style==1.2.8
djangorestframework==3.11.0
docutils==0.15.2
draftjs-exporter==2.1.7
filebrowser-safe==0.5.0
future==0.18.2
grappelli-safe==0.5.2
gunicorn==19.9.0
html5lib==1.0.1
idna==2.8
jmespath==0.9.4
l18n==2018.5
Mezzanine==4.3.1
oauthlib==3.1.0
Pillow==6.2.2
psycopg2-binary==2.8.4
pycparser==2.19
PyJWT==1.7.1
Pyphen==0.9.5
python-dateutil==2.8.1
python-decouple==3.3
python3-openid==3.1.0
pytz==2019.3
rcssmin==1.0.6
requests==2.22.0
requests-oauthlib==1.3.0
rjsmin==1.1.0
s3transfer==0.3.2
six==1.14.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
sqlparse==0.3.0
tinycss2==0.6.1
tzlocal==2.0.0
Unidecode==1.1.1
urllib3==1.25.8
wagtail==2.8.2
wagtail-gallery==0.1.1
wagtailmenus==3.0
WeasyPrint==45
webencodings==0.5.1
whitenoise==5.0.1
Willow==1.3
pandas

Please find the list of apps under

INSTALLED_APPS = [
    'account.apps.AccountConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.postgres',
    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.contrib.modeladmin',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',
    'modelcluster',
    'taggit',
    'empoweru',
    'avatar',
    'assessment',
    'home',
    'week',
    'widget_tweaks',
    'wagtailmenus',
    'crispy_forms',
    'imagekit',
    'storages',
    'wagtail_gallery',
    'wagtail.contrib.routable_page',
    'django_social_share',
    'webpack_loader',
    'dashboard',
    'rest_framework',
]

Please find the MIDDLEWARE section below:

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
    'wagtail.core.middleware.SiteMiddleware',
    'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]

Can someone please help us resolve the issue?

1

There are 1 best solutions below

0
On

The wagtail.core.middleware.SiteMiddleware middleware class was deprecated in Wagtail 2.9 and removed in 2.11. If you still have code in your project that references request.site then you should replace the entry in MIDDLEWARE with 'wagtail.contrib.legacy.sitemiddleware.SiteMiddleware'; if not, you should remove it.

Generally, it's recommended to upgrade Wagtail one point release at a time (2.8, 2.9, 2.10...), checking the release notes for each one and addressing any deprecation warnings in the console as they come up.

Note that this will only fix the No module named 'wagtail.core.middleware' error - with this fixed, the 'django.contrib.wagtail' error will probably still remain and need further investigation.