How do I set, temporarily, the PYTHONPATH environment variable just before executing a Python script?
In *nix, I can do this:
$ PYTHONPATH='.' python scripts/doit.py
In Windows, this syntax does not work, of course. What is the equivalent, though?
To set and restore an environment variable on Windows’ command line requires an unfortunately “somewhat torturous” approach…:
You could use a little auxiliary Python script to make it less painful, e.g.
to be called as, e.g.,
(I’ve coded it so it works for any subprocess, not just a Python script — if you only care about Python scripts you could omit the second python in the cal and put ‘python’ in
sys.argv[i-1]in the code, then usesys.argv[i-1:]as the argument for subprocess.call).