当我尝试运行python manage.py runserver时出现此错误:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 307, in execute
settings.INSTALLED_APPS
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named settings
我的virtualenv中有python 2.7。我在堆栈跟踪的最后几行注意到奇怪的事情,最后一行之前的行有这样的路径:/lokvi_env/lib/python2.7
等
但最后一行就像System/Library/Frameworks
等,所以似乎路径已经从virtualenv变为系统。好吗?
答案 0 :(得分:3)
您需要导入settings
模块
from django.conf import settings
答案 1 :(得分:0)
哦,这不是特定于python路径的问题,对不起。我只需要在我的项目中的设置模块中__init__.py
,因为没有设置它试图在python lib中找到它而且我不相信。