DJANGO_SETTINGS_MODULE undefined with pycharm

I have a problem with DJANGO_SETTINGS_MODULE. I use Pycharm and in the project settings -> Django support, everything is installed and enabled. However, I get the following error when trying to import into 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 anyone have any idea what's wrong?

+4
source share
2 answers

Check out this link . In particular, you want to install 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 is to go to File-> Settings -> Django Support -> and make sure that the fields Django Root, Settings.py and Manage.py are correct.

+8
source

After Dan Hurst answered, I worked for me, but it was not clear where to set the environment variable. You can find the setting in the menu item:

Run -> Edit Configurations...

Expand the Django Server option on the left side, and then select your project. There you will find the Environment Variables: setting. Remember to use a dotted path like Muspy.settings , not a file path.

Dan, I would answer your answer, but I have no reputation.

+4
source

All Articles