How to Set Environment Variables in Pycharm

How to set environment variables in PyCharm?

You can set environmental variables in Pycharm's run configurations menu.

  1. Open the Run Configuration selector in the top-right and cick Edit Configurations...

Edit Configurations...


  1. Select the correct file from the menu, find Environmental variables and click ...

Environment variables


  1. Add or change variables, then click OK

Editing environmental variables

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:

Sample 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



Leave a reply



Submit