Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Django error ModuleNotFoundError: No module named 'corsheaders' [closed]

Hey guys i am getting the below error when i have corsheaders installed, any idea why im getting the below error message as i am out of ideas.

installed:
Python 3.7.2

certifi==2018.11.29

chardet==3.0.4

Django==2.1.7

django-cors-headers==2.4.0

django-mssql==1.8

django-oauth-toolkit==1.2.0

djangorestframework==3.9.1

idna==2.8

oauthlib==3.0.1

pytz==2018.9

requests==2.21.0

urllib3==1.24.1

(Oauth) C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth>Scripts\python.exe mysite\manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03AC8C48>
Traceback (most recent call last):
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\core\management\__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\apps\registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\Users\michael.mountford\OneDrive\Programming\matt-mikes-practice\Oauth\lib\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 'corsheaders'
like image 281
MichaelMountford Avatar asked Dec 01 '25 05:12

MichaelMountford


2 Answers

This could also be a case of having missed , at the end of corsheaders, while adding it in INSTALLED_APPS. Just check once.

like image 96
Amiay Narayan Avatar answered Dec 03 '25 19:12

Amiay Narayan


I had the same problem. If 'corsheaders' is in your INSTALLED_APPS and 'corsheaders.middleware.CorsMiddleware' is in your MIDDLEWARE then something to check is your Virtualenvironment.

Go into the /venv folder and look for the 'corsheaders' folder in /site-packages.

In my case, I had duplicated my project folder so that when I did pip install django-cors-headers it installed in the ORIGINAL project's venv. That may be why recreating the venv worked for MichaelMountford.

like image 42
Owen Avatar answered Dec 03 '25 18:12

Owen