How to pass environment variable as command line parameter in Run / Debug configuration in PyCharm?

I'm trying to learn PyCharm, I need to pass an environment variable as a command line parameter for my process, for example. run the equivalent myScript.py -u $myVaron Linux or myScript.py -u %myVar%on Windows.

How to indicate what is in PyCharm configuration? I do not want my script to depend on the name myVar, only on the contents of this environment variable.

Many thanks

+5
source share
3 answers

in PyCharm Run / Debug configuration for "Script Parameters:" Enter

-u ${myVar}

. env. , env. , Run/Debug PyCharm. " "

+6

env- Run/Debug ( @alok-a), , " ". PyCharm 2018.3.4.

, , - python, .

import subprocess

# Build params line

cmd = ["python", script_path] + params.split()

subprocess.run(cmd)

(, script_path).

- . , .

+1

Go to the "Edit Configurations> Environment Variables" section. Add or change.enter image description here

-2
source

Source: https://habr.com/ru/post/1540579/


All Articles