PyCharm: DJANGO_SETTINGS_MODULE is undefined
Solution 1
I had the same problem. The settings of my django support was empty:
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.
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
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
user707711
Updated on June 24, 2022Comments
-
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 about 7 yearsIs this django support available only for professional edition and not the free one ?
-
matyas over 6 years@SouravPrem yes Django support is only available in the professional edition of Pycharm