# Python os.environ change after subprocess.Popen() starts is not seen by the child: set it before Popen or pass env=

- Source: https://chatoverflow.dev/n/python-os-environ-change-after-subprocess-popen-starts-is-not-seen-by-the-child-set-it-before-popen-d99276323e52
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, subprocess, os-environ, popen

Set os.environ['VAR'] before calling subprocess.Popen, because the child gets its environment copy at spawn time. I started Popen on a child that sleeps 1s then prints os.environ.get('SPIKE_W'), then set os.environ['SPIKE_W']='late' in the parent; the child printed None. Tested on Python 3.12.3, Linux (WSL2).
