How to set environment variables in PyCharm?
You can set environmental variables in Pycharm's run configurations menu.
- Open the Run Configuration selector in the top-right and cick
Edit Configurations...
- Select the correct file from the menu, find
Environmental variables
and click...
- Add or change variables, then click
OK
You can access your environmental variables with os.environ
import os
print(os.environ['SOME_VAR'])
Why PyCharm does not recognize user environment variables configuration?
OK,
apparently for terminal and run,
there are different places where you define configurations.
During the whole time,
I used the configurations at the top right corner,
While there is another place in the terminal settings
where it is also possible to configure the Terminal environment variables only.
Anyhow it solved the problem--> also necessary to restart Pycharm after adding each parameter.
Hope it will help someone :)
Set the same environment variables for all configurations in PyCharm
Found solution here, it is about installing plugin EnvFile and put all environment variables to a file.
The installation is pretty simple:
Preferences > Plugins > Browse repositories... > Search for "Env File" > Install Plugin.
Then, create a file, called environment.env which contains:
DATABASE_URL=postgres://127.0.0.1:5432/my_db_name
DEBUG=1 Then I went
to Run -> Edit Configurations, and I followed the steps in the next image:
P.S. in the question by link there are 2 answers with many votes (for now: 44 and 42). And accepted works here, but other with more votes and large screenshots - don't, because it is how to set environment variables in general.
Related Topics
Reading from a Frequently Updated File
Python: Importing a Sub‑Package or Sub‑Module
How to Get the Ip Address from a Nic (Network Interface Controller) in Python
Local () Variable Referenced Before Assignment
Pyaudio Working, But Spits Out Error Messages Each Time
Python Unexpected Eof While Parsing
How to Use an Image for the Background in Tkinter
Converting String with Utc Offset to a Datetime Object
Selenium Compound Class Names Not Permitted
Collapse Multiple Submodules to One Cython Extension
What Is the Internal Precision of Numpy.Float128
How to Know the Angle Between Two Vectors
Parsing Date with Timezone from an Email
Thread Starts Running Before Calling Thread.Start
In Python, Differencebetween ".Append()" and "+= []"