Resolve environment variables in run configuration

Answered

Hi,

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?

Cheers,

Graham

5 comments
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?

0
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:

/Applications/PyCharm.app/Contents/MacOS/pycharm

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.


Cheers,

Graham

0
Comment actions Permalink

Interesting...
Where do you set those environment variables?

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

0
Comment actions Permalink

Environment variables are set in my .bash_profile.

 

Run config is:

 

Where the contents of 'Parameters:' are essentially:

--db-username

${USERNAME}

--db-password

${USERPASS}

--data-directory

"${HOME}/Desktop/foo"

--dataset-name

foo

run

 

 

0
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 https://youtrack.jetbrains.com/issues/PY

#com.intellij.execution.configurations.GeneralCommandLine

0

Please sign in to leave a comment.