Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined. January 25, 2010

Filed under: Django,Error,Python — Rupert Bates @ 12:14 pm

If you get the following error when trying to use a Django package from the interactive prompt in Pydev:
“ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.”

You can solve it by setting the required environment variable in the __init__.py file of your app as follows:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
Advertisements