Django giving error ImportError: No module named 'corsheaders'

Saras Arya picture Saras Arya · Nov 2, 2016 · Viewed 12.8k times · Source

I am a newbie to Django and trying to enable CORS for my server. I couldn't find a built-in solution so I went with django-cors-headers. I am running my server in conda environment on python 3.5 in Ubuntu 15.04. So I installed it with pip3 install django-cors-header. When I do pip3 list it shoes django-cors-header installed at version 1.2.2. In my django app I did.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'polls',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

But when I run python3 manage.py runserver It stops saying ImportError: No module named 'corsheaders'. I have read all SO posts regarding it but none seem to solve my problem. Kindly help

Answer

Saras Arya picture Saras Arya · Nov 2, 2016

Originally I did pip3 install django-cors-headers, instead by fluke I tried pip install django-cors-headers and voila it worked.

Hope it helps somebody