Django Error Module 'Whitenoise' not found - python

I'm using whitenoise to deploy static files in prod, so according to whitenoise's docs, it's recommended to use it in development too.
So I followed the documentation and added the following to my settings.py file:
INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'django.contrib.admin',
...other
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...other
]
But when I run the server using python manage.py runserver 0.0.0.0:8000, I get the error
ModuleNotFoundError: No module named 'whitenoise'
Full stack trace:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/path/to/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/path/to/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/path/to/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/path/to/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/path/to/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/path/to/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path/to/venv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/path/to/venv/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'whitenoise'
I checked using pip freeze and the module IS installed (v5.0.1) along with django 3.0.4. So why am I getting that error?

this issue will be resolved by installing whitenose module to your virtual environment or globally.
pip install whitenoise

Related

ModuleNotFoundError: No module named 'crispy_formsmain'

Please help me as I am new to Django and I am learning out of my curiosity. I tried to find the solution but couldn't. I have spent 2 days to find the appropriate solution. Please help.
I cloned the repository from github and it gives me the error as follows:
(env) C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File `"C:\ProgramFiles\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 892, in run`
self._target(*self._args, **self._kwargs)
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-`packages\django\core\management\commands\runserver.py", line 110, in inner_runautoreload.raise_last_exception()`
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Tenzin Karma\Desktop\critique\Wrappers-India-Online-master\env\lib\site-packages\django\apps\config.py", line 224, in create
import_module(entry)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.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 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'crispy_formsmain'
Looking at the error , it looks like you are missing the module. You can try
pip install django-crispy-forms
Also from the error logs , I can see you are using virtual env, please make sure you install the package in the same venv.
Once installed, if it still shows the error , then
in settings.py installed apps add crispy_forms In settings.py add CRISPY_TEMPLATE_PACK = 'bootstrap4

Django No module named 'responsive_images'

Getting the following error when ported Django from 2.7 to 3.6
Traceback (most recent call last):
File "manage.py", line 21, in <module>main()
File "manage.py", line 17, in main execute_from_command_line(sys.argv)
File "C:\Django\CampusStore\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute()
File "C:\Django\CampusStore\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute django.setup()
File "C:\Django\CampusStore\venv\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS)
File "C:\Django\CampusStore\venv\lib\site-packages\django\apps\registry.py", line 91, in populate app_config = AppConfig.create(entry)
File "C:\Django\CampusStore\venv\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files (x86)\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'responsive_images'
You have to make sure you add the library to your INSTALLED_APPS list in settings.py. It's useful to keep in mind the library name as it's downloaded is usually different than it's name in pip. for Example this is installed with pip install django-responsive-images, but responsive_images is what you should include in your INSTALLED_APPS.

ModuleNotFoundError: No module named 'widget_tweaks'

I'm writing project using docker and django (2.1).
I've installed module 'django-widget-tweaks' inside a container and added 'widget_tweaks' to INSTALLED_APPS. When I start project using docker-compose up everything works well, but when I want to run something like docker-compose run <container name> python manage.py test in another terminal an error occurs.
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'widget_tweaks'
But when I directly run the same command python manage.py test inside a docker container, it works. widget-tweaks has been installed both on container and on my machine. Could you advice something to solve the problem?
Thanks in advance!

Django ModuleNotFoundError when adding app

I'm using Visual Studio with Python tools to develop my Django project. I've create an app through the IDE. However after adding the app into the INSTALLED_APPS in my settings.py, it is always giving me ModuleNotFound Error
This is the directory structure.
This is how I've added the app
INSTALLED_APPS = [
# Add your apps here to enable them
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'kleis',
]
Stacktrace
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000228FCA30A60>
Traceback (most recent call last):
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\core\management\__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'kleis'
I tried with the above solutions but didnt get solved either.
If we miss to import the path in the newly created urls.py we will be seeing this error,
from django.urls import path (refer:https://docs.djangoproject.com/en/2.0/intro/tutorial01/#creating-a-project)
this will solve this error
Good Luck

JetBrains Pycharm - Getting error while debugging my project

I just switched to Mac from windows.
I imported my project in pycharm from GitHub but it is giving unknown errors.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10b75f6a8>
Traceback (most recent call last):
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/Users/rajababu/anaconda/lib/python3.6/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 'import_export'
I think import_export is not in your INSTALLED_APPS.
Install import_export with pip
pip install django-import-export
and try again.
You need to install the import_export plugin. You can do this in PyCharm using File > Settings > Project Interpreter and press the "+" icon (search for it and install it). Make sure to add import_export to your INSTALLED_APPS variable in your settings as well.

Categories

Resources