[SOLVED] How to set environment variables in PyCharm?
Problem
When you start a Django project you might find difficulties setting up the environment variables in PyCharm. Especially if we want to set them manually. In our case, we want to put these things.
export DATABASE_URL=postgres://127.0.0.1:5432/my_db_name
export DEBUG=1
You can also try to edit environment variables from Preferences-> Build, Execution, Deployment->Console->Django Console but it will only set variables for the interpreter.
We will now fix this problem step by step.
Solution:
First, go to 'Run/Debug configuration' on the top right corner and click 'Edit configurations'.
Then you can see 'Environment Variables' on the newly opened tab. In my case, it is in the red-pointed area. All your environment variables are listed here.
Now click on 'Edit Environment Variables' and you will be able to edit or add your desired environment variables. You can add variables just by clicking the plus sign where the arrow is pointed.
After adding environment variables hit the 'OK' button and you are now good to go.
You will also be able to view your environment variables using this code snippet.
import os
print(os.environ['SOME_VAR'])
Thank you for reading till the end. Don't hesitate to comment down below if you face any further problems regarding this issue.