How do I make environment variable changes stick in Python?

You can using SETX at the command-line.

By default these actions go on the USER env vars.
To set and modify SYSTEM vars use the /M flag

import os
env_var = "BUILD_NUMBER"
env_val = "3.1.3.3.7"
os.system("SETX {0} {1} /M".format(env_var,env_val))

Leave a Comment