Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass an environment variable to Parameters in PyCharm's Run/Debug configurations?

Tags:

pycharm

The parameters that I need to pass to my Python program use some environment variables.

Example:

This is how I run it on the terminal:

export BUCKET="/tmp/bucket"
python main.py --input $BUCKET/input --output $BUCKET/output

On PyCharm, I created a Run/Debug configuration with an environment variable called BUCKET and passed the following string as parameters: --input $BUCKET/input --output $BUCKET/output.

When PyCharm executes the program, it doesn't pick up the value of BUCKET as /tmp/bucket. It considers $BUCKET to be a string.

I also tried using ${BUCKET} instead of $BUCKET but that doesn't work either.

Is there some way to pass variables?

Note: The reason I want to do this is that I have a large number of parameters in my real code. I have only provided a toy example above. I want to be able to update an environment variable only in one place.

like image 542
xennygrimmato Avatar asked Nov 06 '22 19:11

xennygrimmato


1 Answers

I encountered the same problem a few days back. I found a plugin called EnvFile. EnvFile Using this you can have an env file exported before running the script. After installing it, you'll get an extra tab EnvFile in your configuration. Select your environment file there. It is specific to the configuration. Now, every time you run the configuration environment variables will be exported. EnvFile Tab My .env file

Env File

like image 88
Dharanidhar Reddy Avatar answered Dec 03 '22 00:12

Dharanidhar Reddy