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
Please sign in to leave a comment.
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?
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
Interesting...
Where do you set those environment variables?
Could you please also share a screenshot of your Run/Debug configuration?
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
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
Sergey Karpov I have a similar issue, which seems configuration dependent. When I execute a simple Python test run configuration, my system environmental variables are present, and my env parameters expand. For example this simple test prints my local $http_proxy twice.
However, if I try to use variable expansion when executing a Docker run configuration the environmental variables are not expanded
You can see the literal value ${http_proxy}.
I am not sure where to report this behavior but I found this thread and thought it may be relevant or at least you could point me in the right direction.
Hi Mr Waffles,
I'm not sure it's supposed to work in Build args. We probably do not parse it that way and just pass it as a text.
It may be worth filing a feature request to https://youtrack.jetbrains.com/issues/IDEA
If I'm wrong and there is a way to make it work, then guys from the IDEA team will let you know.
Great thanks! Found it there https://youtrack.jetbrains.com/issue/IDEA-252301