Python 导入错误 django corsheaders
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26072426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import error django corsheaders
提问by shebeer
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
我是 Django 的初学者。我正在做基于它的项目。项目有两个阶段。我完成了第一阶段并将代码上传到亚马逊 ec2 实例。完成第二阶段后,我添加了一些包,如python-social-auth, django-cors-headers, django-easy-maps, crispyforms。但现在它显示 corsheaders 的导入错误,这是我检查过的虚拟环境和 corsheaders 包的回溯
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
任何建议请
回答by avi
From your traceback, it looks like you are not running the Django app in virtual environment. You could do two things:
从您的回溯来看,您似乎没有在虚拟环境中运行 Django 应用程序。你可以做两件事:
Install
django-corsheaderssystem 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-corsheadersis installed in virtual environment.)
在
django-corsheaders系统范围内安装,以便它可用于您的应用程序,无论是否有虚拟环境或者您激活虚拟环境并运行 django 应用程序(因为您已经确认
django-corsheaders已安装在虚拟环境中。)
回答by Rafael Corzo
Using pip:
使用pip:
pip install django-cors-headers
Using pipenv:
使用pipenv:
pipenv install django-cors-headers
回答by Faysal Ahmed
I had the same problem after installed via pip. Then i downloaded source and manually installed the django-cors-headersafter that the problem was gone.
通过pip安装后我遇到了同样的问题。然后我下载了源代码并手动安装了django-cors-headers之后问题就消失了。
Hope that helps.
希望有帮助。
回答by CPMaurya
Try This.
尝试这个。
pip install --user django-cors-headers

