Hello I am trying to run the following python script against an already initialized virtual environment:
import subprocess
# List of Poetry commands to be executed
poetry_commands = [
"poetry install",
"export PARAM_1=<value>",
"export PARAM_2=<value>",
.
.
"export PARAM_N=<value>",
"poetry run start"
]
# Iterate over each Poetry command and execute it
for command in poetry_commands:
try:
# Run the command in the shell, wait for it to finish
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Command '{command}' failed with error code {e.returncode}")
For some reason the script completes, however the poetry run start
command fails due to export params not being applied. How can I assure that the export env variables are correctly set after poetry install
?
You are running each command in its own separate shell.
Each shell is created, running an export statement and then destroyed,
To correctly pass environment variables, pass
env
to subprocess.