问题
i am a beginner in django. i am doing project based on it. project has two stages. i completed first phase and uploaded the code to amazon ec2 instance. after completing second phase i added some packages like python-social-auth
, django-cors-headers
, django-easy-maps
, crispyforms
. but now it is showing import error for corsheaders and this the traceback
i have checked virtual environment and corsheaders package is ther
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named corsheaders
any suggestions please
回答1:
Using pip
:
pip install django-cors-headers
Using pipenv
:
pipenv install django-cors-headers
回答2:
I had the same problem after installed via pip. Then i downloaded source and manually installed the django-cors-headers
after that the problem was gone.
Hope that helps.
回答3:
From your traceback, it looks like you are not running the Django app in virtual environment. You could do two things:
Install
django-corsheaders
system wide so it's available to your app, with or without virtual environmentOr you activate the virtual environment and run the django app (since you have already confirmed that
django-corsheaders
is installed in virtual environment.)
来源:https://stackoverflow.com/questions/26072426/import-error-django-corsheaders