0

I want to modified the environment variable via python script/file.

I tried using os.environ but it does not work, as below:

export TARGET=original_target_value
python
import os
print(os.environ["TARGET"])  # "original_target_value"
os.environ["TARGET"] = "modified_target_value"
print(os.environ["TARGET"])  # "modified_target_value"
quit()
import os
print(os.environ["TARGET"])  # "original_target_value"  # Parent TARGET value didn't chang

enter image description here

Python | os.environ object: We can also modify os.environ but any changes will be effective only for the current process where it was assigned and it will not change the value permanently.

Is there anyway to change the environment variables permanently (change the parent environment variable)?

GSZ1006
  • 1
  • 1
  • 2
    Does this answer your question? [Is it possible to set an environment variable from Python permanently?](https://stackoverflow.com/questions/17657686/is-it-possible-to-set-an-environment-variable-from-python-permanently) – slothrop Jul 05 '23 at 12:58

0 Answers0