I am trying to use subprocess.run(['python3.9', "scripts/example.py"], check=True).
example.py uses a module, that I have added to the PYTHONPATH.
However,
whenever I run the above line, the module is not found.
The confusing part for me is, that printing sys.path inside of example.py I do see the path to my module.
But when I am running os.system("which python") or os.system("echo $PYTHONPATH") inside example.py, it returns/prints nothing.
subprocess.run([sys.executable, 'scripts/example.py', check=True), unless of course you really do wantpython3.9explicitly and nothing else (which would be surprising). -- And finally, you should check the doc for theenvparameter ofsubprocess.run.importthe code you want to run, and not run it in a subprocess at all.