How to Solve Error Message ModuleNotFoundError : No module named ‘whitenoise’ when executing python manage.py collectstatic

Posted on

This is another article which has a focus on how to solve an error message exist while executing the command ‘python manage.py collectstatic’. Actually, there is a definition of a specific context of ‘whitenoise’ in the settings.py file. It exist in the file of ‘settings.py’. The definition for the context exist as follows :

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

The above source code definition is useful in order to load static file like ‘css’, ‘js’ or ‘images’ in the Django-based application. Actually, the impact of the above definition exist after executing the command of ‘python manage.py collectstatic’.

(env) user@hostname:~/python/django/todoproject$ python manage.py collectstatic
Traceback (most recent call last):
  File "manage.py", line 21, in 
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 162, in handle
    if self.is_local_storage() and self.storage.location:
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 216, in is_local_storage
    return isinstance(self.storage, FileSystemStorage)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/functional.py", line 256, in inner
    self._setup()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/contrib/staticfiles/storage.py", line 498, in _setup
    self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/files/storage.py", line 358, in get_storage_class
    return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/home/user/python/django/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 953, in _find_and_load_unlocked
  File "", line 219, in _call_with_frames_removed
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'whitenoise'
(env) user@hostname:~/python/django/todoproject$ 

The solution for the above error message is definitely simple. It is because the information is already exist in the error message. It is because there is no module with the name of ‘whitenoise’. So, solving the problem is just installing that module. Below is the step for installing the module to solve the problem :

1Just install the suitable module by executing the following command :

(env) user@hostname:~/python/django/todoproject$ pip install whitenoise
Collecting whitenoise
  Downloading whitenoise-5.0.1-py2.py3-none-any.whl (20 kB)
Installing collected packages: whitenoise
Successfully installed whitenoise-5.0.1
(env) user@hostname:~/python/django/todoproject$

Actually, if there is no other requirement and everything is running well. The execution of the ‘python manage.py collectstatic’ will be a success. Below is the execution of the command if it is a success :

(env) user@hostname:~/python/django/todoproject$ python manage.py collectstatic

119 static files copied to '/home/user/python/django/todoproject/todoproject/static'.
(env) user@hostname:~/python/django/todoproject$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
March 15, 2020 - 09:07:23
Django version 2.2.6, using settings 'todoproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

One thought on “How to Solve Error Message ModuleNotFoundError : No module named ‘whitenoise’ when executing python manage.py collectstatic

Leave a Reply