PyCharm: DJANGO_SETTINGS_MODULE is undefined

18,385

Solution 1

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

PyCharm project config

Solution 2

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.

Solution 3

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 .

Solution 4

"Standalone Django scripts"

Solution 5

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

Share:
18,385
user707711
Author by

user707711

Updated on June 24, 2022

Comments

  • user707711
    user707711 almost 2 years

    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?

  • Sourav Prem
    Sourav Prem about 7 years
    Is this django support available only for professional edition and not the free one ?
  • matyas
    matyas over 6 years
    @SouravPrem yes Django support is only available in the professional edition of Pycharm