21

I am using PyCharm IDE and when I run any file.py I get this error:

..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.

How to configure DJANGO_SETTINGS_MODULE environment variable in PyCharm?

pbaranski
  • 22,778
  • 19
  • 100
  • 117
user707711
  • 261
  • 1
  • 3
  • 9

6 Answers6

29

I had the same problem. The settings of my django support was empty:

PyCharm project config

10

I had the same problem as well, and the fix in IntelliJ IDEA is not obvious (especially since there is no notification with a "fix-it" link for this problem).

You'll find you need to set Settings to your Django project's settings.py file in Project Structure > Modules > [your Django project's name] > Django.

Now you know where to stick it.

Will
  • 5,654
  • 2
  • 23
  • 26
9

You can go to the tool bar which shows a dropdown and select your project ->edit configuration. There in the Environment variable area enter DJANGO_SETTINGS_MODULE mysite.settings and save .

Kapil
  • 9,469
  • 10
  • 40
  • 53
8

"Standalone Django scripts"

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
3

I faced the same problem and proposed solutions did not work.

I solved it by going in "File > Settings..." Then search for "Django console" and add the following Environment variable: DJANGO_SETTINGS_MODULE=mysite.settings

kenshuri
  • 472
  • 3
  • 11
0

for new commers, below is the additional info'.

where you can find the place to set DJANGO_SETTINGS_MODULE in pycharm 2019.1 is:

config -> language and frameworks -> Django's right pain.

the column just below the django project root you can cite your config file path.

and the environment variables column you can set DJANGO_SETTINGS_MODULE value.

k-brahma
  • 41
  • 3