Subprocess.call or Subprocess.Popen cannot use executables that are in PATH (Linux/Windows) Subprocess.call or Subprocess.Popen cannot use executables that are in PATH (Linux/Windows) windows windows

Subprocess.call or Subprocess.Popen cannot use executables that are in PATH (Linux/Windows)


You can control the environment variables available in the spawned subprocess by passing a mapping with the env keyword argument. E.g.

proc = subprocess.Popen(args, env={'PATH': '/some/path'})

Or to inherit PATH from the system environment variable, without necessarily chucking in everything else from the system environment:

proc = subprocess.Popen(args, env={'PATH': os.getenv('PATH')})

It might be easier/simpler just to use an absolute path, though.


Ok here is how I got it to work.

env = os.environproc = subprocess.Popen(args, env=env)


I struggled with this myself until I found this python bug report.

"If you add a directory into PATH on Windows so that the directory is in quotes, subprocess does not find executables in it." Since the quotes aren't required by windows removing them fixes my problem (in 2.7).