DJANGO_SETTINGS_MODULE is undefined with pycharm

django, pycharm

Solution

Check out this link. Specifically, you want to set the `Environmental Variable` in the configuration. By default, you will see `PYTHONBUFFERED = 1`, and you will want to add `DJANGO_SETTINGS_MODULE = project.settings` - obviously replacing `project` with the actual name of your project.

Another good thing to do is to go to `File-> Settings -> Django Support ->` and be sure that your Django Root, Settings.py, and Manage.py fields are correct.

Problem

I have the DJANGO_SETTINGS_MODULE problem. I am using Pycharm and under Project Settings -> Django Support everything is set and enabled. Nevertheless I get following error while trying do an import in models.py: ``` from django.db import models C:\Python27\python.exe C:/Users/Grimbo/PycharmProjects/Muspy/poll/models.py Traceback (most recent call last): File "C:/Users/Grimbo/PycharmProjects/Mus/poll/models.py", line 1, in <module> from django.db import models File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <module> if DEFAULT_DB_ALIAS not in settings.DATABASES: 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. ``` print(sys.path): ``` ['C:\\Program Files (x86)\\JetBrains\\PyCharm 2.6.3\\helpers\\pydev', 'C:\\WINDOWS\\SYSTEM32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Users\\Grimbo\\PycharmProjects\\Mus'] ``` Does someone has an idea what's wrong?

Original source