akshay bhan
akshay bhan

Reputation: 1

neo4django issues: ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined

I was trying to run the statement:

from neo4django.db import models

which resulted in the following error:

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.

Kindly help me out with this issue.

Upvotes: 0

Views: 77

Answers (1)

William Lyon
William Lyon

Reputation: 8546

That error is caused because the environment variable DJANGO_SETTINGS_MODULE is not set. This variable is used to tell Django where to look for settings. For example:

export DJANGO_SETTINGS_MODULE=mysite.settings

Alternatively you can call django.conf.settings.configure() to initialize settings. You can read more about it in the docs here.

If you are only running tests for neo4django you can use the included neo4django test settings as described here:

expor DJANGO_SETTINGS_MODULE=neo4django.tests.test_settings

Upvotes: 1

Related Questions