neo4django问题:ImportError:无法导入设置,因为环境变量DJANGO_SETTINGS_MODULE未定义

时间:2016-12-19 17:31:34

标签: python neo4j neo4django

我试图运行声明:

from neo4django.db import models

导致以下错误:

Traceback (most recent call last):
  File "<pyshell#38>", line 1, in <module>
    from neo4django.db import models
  File "C:\Python27\lib\site-packages\neo4django\db\__init__.py", line 68, in <module>
    if getattr(_settings, 'NEO4DJANGO_PROFILE_REQUESTS', False):
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in inner
    self._setup()
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

由于未设置环境变量DJANGO_SETTINGS_MODULE而导致该错误。此变量用于告诉Django在哪里查找设置。例如:

export DJANGO_SETTINGS_MODULE=mysite.settings

或者,您可以致电django.conf.settings.configure()初始化设置。您可以在文档here中详细了解它。

如果您只是运行neo4django的测试,您可以使用所包含的neo4django测试设置here:

expor DJANGO_SETTINGS_MODULE=neo4django.tests.test_settings