Django/Python 环境错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/911085/
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
Django/Python EnvironmentError?
提问by simi
I am getting an error when I try to use syncdb
:
当我尝试使用时出现错误syncdb
:
python manage.py syncdb
Error message:
错误信息:
File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 83, in __init__
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
EnvironmentError: Could not import settings '/home/simi/workspace/hssn_svn/hssn' (Is it on sys.path? Does ti have syntax errors?): Import by filename is not supported.
I'm a newbie with Django/Python, but I can't figure this error out after having researched online for a while now.
我是 Django/Python 的新手,但在网上研究了一段时间后我无法弄清楚这个错误。
回答by miku
Your trace states:
您的跟踪说明:
Import by filename is not supported.
Which might indicate that you try to import (or maybe set the DJANGO_SETTINGS_MODULE) to the full python filename, where it should be a module path: your.module.settings
这可能表明您尝试导入(或设置 DJANGO_SETTINGS_MODULE)到完整的 python 文件名,它应该是一个模块路径: your.module.settings
You could also try to specify your DJANGO_SETTINGS_MODULE directly from command line, like:
您也可以尝试直接从命令行指定 DJANGO_SETTINGS_MODULE,例如:
$ DJANGO_SETTINGS_MODULE=your.module.settings ./manage.py syncdb
回答by Luper Rouch
Make sure your settings.py file is in the same directory as manage.py (you will also have to run manage.py from this directory, i.e. ./manage.py syncdb), or make the environment variable DJANGO_SETTINGS_MODULE point to it.
确保您的 settings.py 文件与 manage.py 位于同一目录中(您还必须从该目录运行 manage.py,即 ./manage.py syncdb),或者让环境变量 DJANGO_SETTINGS_MODULE 指向它。
回答by EoghanM
Another thing that gives this error is permissions - very hard to track down.
导致此错误的另一件事是权限 - 很难追踪。
Solution for me was to move <myproject>
to /var/www/<myproject>
and do chown -R root:root /var/www/<myproject>
我的解决方案是移至<myproject>
/var/www/<myproject>
并执行 chown -R root:root /var/www/<myproject>