I'm trying to get subprocess.Popen to run a python script but I keep getting the following error: /bin/sh: python: command not found. The script takes a yaml file as an argument. I've tried this line both with and without shell=True. The script runs fine when I run it with the python command in my Linux terminal. What am I doing wrong?
process = subprocess.Popen(
['python', PATH_TO_PYTHON_SCRIPT, PATH_TO_CONFIG_FILE],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stdin=subprocess.PIPE, shell=True)
with process.stdout, open(processing_log, 'ab') as f_in:
for line in iter(process.stdout.readline, b''):
f_in.write(line)
Popen(['/path/to/python.exe', PATH_TO_PYTHON_SCRIPT, ...andshell=False. Does that work? It may hint at what the core issue is. You can find the absolute path to the executable by runningwhich pythonin your linux terminalshell=Truethis will never work, because all the arguments but the first one (python) will be ignored. Mind, thatpythonisn't in yourPATHis a whole different issue.