jamemecander
jamemecander

Reputation: 11

pythonanywhere corsheaders module not found error

I set it up as below, but there is an error. I need your help.

  1. Set the corsheader in setting.py file
  2. Pip install django-cors-headers installed.
  3. pip3 install django-cors-head installed.

Even though we handled it as above, there is an error as below.

2020-11-10 07:10:05,116: ***************************************************
2020-11-10 07:10:05,117: If you're seeing an import error and don't know why,
2020-11-10 07:10:05,117: we have a dedicated help page to help you debug: 
2020-11-10 07:10:05,117: https://help.pythonanywhere.com/pages/DebuggingImportError/
2020-11-10 07:10:05,117: ***************************************************
2020-11-10 16:11:05,533: Error running WSGI application
2020-11-10 16:11:05,542: ModuleNotFoundError: No module named 'corsheaders'
2020-11-10 16:11:05,543:   File "/var/www/abc_com_wsgi.py", line 16, in <module>
2020-11-10 16:11:05,543:     application = get_wsgi_application()
2020-11-10 16:11:05,543: 
2020-11-10 16:11:05,543:   File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2020-11-10 16:11:05,543:     django.setup(set_prefix=False)
2020-11-10 16:11:05,543: 
2020-11-10 16:11:05,543:   File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2020-11-10 16:11:05,543:     apps.populate(settings.INSTALLED_APPS)
2020-11-10 16:11:05,544: 
2020-11-10 16:11:05,544:   File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
2020-11-10 16:11:05,544:     app_config = AppConfig.create(entry)
2020-11-10 16:11:05,544: 
2020-11-10 16:11:05,544:   File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
2020-11-10 16:11:05,544:     module = import_module(entry)

setting.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')

ALLOWED_HOSTS = [u'abc.com', 'aa.abc.com',]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
]

MIDDLEWARE = [
'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',
'corsheaders.middleware.CorsMiddleware',
]

pip3 cors-headers install command

pip3.7 install --user django-cors-headers      
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: django-cors-headers in ./.local/lib/python3.7/site-packages (3.3.0)
Requirement already satisfied: Django>=2.0 in /usr/lib/python3.7/site-packages (from django-cors-headers) (2.1)
Requirement already satisfied: pytz in /usr/lib/python3.7/site-packages (from Django>=2.0->django-cors-headers) (2018.5)

Upvotes: 1

Views: 1307

Answers (1)

Filip
Filip

Reputation: 676

Your web app is running in virtual environment myvenv but you installed the package in .local with --user flag. You need to install it without --user with myvenv virtual environment activated. See: https://help.pythonanywhere.com/pages/InstallingNewModules/

Upvotes: 0

Related Questions