我试图执行
python manage.py runserver
但它引发了一个错误说
ImportError: Could not import settings 'survivalguide.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named survivalguide.settings
我使用python 2.7安装了Anaconda并设置了virtualenv。
我的manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "survivalguide.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我当前的os.path
[
'',
'/Users/KWYI/Documents/Python_Practice/Django_Practice/survivalguide',
'/Users/KWYI/anaconda/envs/PyCon/lib/python27.zip',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/plat-darwin',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/plat-mac',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/lib-tk',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/lib-old',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/lib-dynload',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/site-packages',
'/Users/KWYI/anaconda/envs/PyCon/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg'
]
我现在排除故障几个小时,但仍然无法弄清问题是什么。
感谢您的帮助!
答案 0 :(得分:2)
将DJANGO_SETTINGS_MODULE
设置为'survivalguide.settings'
通常有效,因为manage.py
位于settings.py
上方的目录中。
manage.py
与settings.py
位于同一目录中,这是不常见的。我建议将manage.py
移到父目录中。除非你明白自己在做什么,否则我会避免使用自定义项目布局,否则你可能会遇到更多这样的问题。
如果您不能这样做,您可以将行更改为:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
或者您可以手动将/Users/KWYI/Documents/Python_Practice/Django_Practice/
添加到python路径。