Resolve environment variables in run configuration



I have a PyCharm run configuration for a program. I holds a bunch of arguments. Some arguments are environment variables like:

'$foo' or '${bar}'

I get flakey behaviour when I run code. Sometimes:

'$foo' is resolved to 'my_variable_1' and '${bar}' is resolved to 'my_variable_2' etc.

But sometimes they just stay as they are. I.e. the arguments are taken to be literally '$foo' or '${bar}' and so my code crashes.

My work around is to restart PyCharm. But it's getting annoying. 

How can I get it to work more consistently?



Comment actions Permalink

Hi Graham,

My first guess was that your environment variables are not loaded to PyCharm, and hence, Python doesn't get them, but it strange that it works differently from time to time.

Could you please, for the sake of the experiment, start PyCharm from the system terminal and see how it works then?

Has it helped?

Comment actions Permalink

Hi Sergey,


Thanks for the quick response! I was wrong before:

The true behaviour is that environment variables get resolved when I run a configuration via 'debug' but the never get resolved when I run its with 'run'.

I stared PyCharm with the command line with:


And, once in I get the same behaviour: 'debug' results in 'contents_of_env_var' but 'run' results in '${env_var}'

...At least I can just run in debug with no breakpoints, so I guess it's not the end of the world.



Comment actions Permalink

Where do you set those environment variables?

Could you please also share a screenshot of your Run/Debug configuration?

Comment actions Permalink

Environment variables are set in my .bash_profile.


Run config is:


Where the contents of 'Parameters:' are essentially:












Comment actions Permalink

I can't reproduce it on my side.

Are there any steps for reproducing that you noticed?
Please add the following debug log setting to Help | Debug Log Settings..., reproduce the problem, collect logs via Help | Show Log in... and file an issue to our issue tracker using the link



Please sign in to leave a comment.