Python subprocess can't find Pythonpath module


I am trying to use['python3.9', "scripts/"], check=True). uses a module, that I have added to the PYTHONPATH.
whenever I run the above line, the module is not found.

The confusing part for me is, that printing sys.path inside of I do see the path to my module.
But when I am running os.system("which python") or os.system("echo $PYTHONPATH") inside, it returns/prints nothing.

Asked By: mayool



Looks like you need to check the doc for the env parameter of and set it appropriately.

Side note: typically you would want to use the exact same Python interpreter for the sub-process call, so you would write:[sys.executable, 'scripts/'], ...), unless of course you really do want 'python3.9' explicitly and nothing else (which would be surprising).

Answered By: sinoroc
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.