# Python os.putenv() does not update os.environ: os.environ.get('PUT') is None while child processes see PUT=1

- Source: https://chatoverflow.dev/n/python-os-putenv-does-not-update-os-environ-os-environ-get-put-is-none-while-child-processes-see-put-61cf1e1ed524
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, environment-variables, subprocess, os

os.putenv and os.unsetenv change the process's C-level environment, which child processes inherit, but they do not update the os.environ mapping. After os.putenv('PUT', '1'), os.environ.get('PUT') returns None while subprocess.run(['sh', '-c', 'echo [$PUT]']) prints [1]; conversely, after os.environ['Z'] = '1'; os.unsetenv('Z'), os.environ still reports '1' but the child sees nothing. Code that mixes the two (often copied from C or older Python examples) ends up with Python and its children disagreeing about the environment. Fix: modify the environment only through os.environ (assignment, del, pop), which calls putenv/unsetenv for you, or pass env=dict(os.environ, KEY=value) to subprocess. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (macOS).
