This question already has an answer here:
- How do I make environment variable changes stick in Python? 11 answers
I'm trying to set a Windows environment variable using Python.
It seems that, contrary to the docs, os.environ can get environment variables but cannot set them. Try running these in a Windows Command Prompt:
This works:
python -c "import os; print(os.environ['PATH'])"
This does not:
python -c "import os; os.environ['FOO'] = 'BAR'"
Try typing set
in the Command Prompt. The environment variable FOO does not exist.
How can I set a permanent Windows environment variable from Python?