I want to pass PYTHONPATH as argument to python.exe just like i can do this in java:
java -classpath /somedir/some.jar;/anotherdir MyClass
so i'm looking for something like:
python -PYTHONPATH /somedir/pythonsrc;/anotherdir/pythonsrc mymodule.py
is it possible to do such a think in python? thanks
Noufal Ibrahim
73.2k13 gold badges141 silver badges174 bronze badges
asked Apr 6, 2012 at 13:48
Jas
15.3k27 gold badges103 silver badges159 bronze badges
2 Answers 2
Try to set the environement variable PYTHONPATH before launching python :
On windows :
set PYTHONPATH=/somedir/pythonsrc;/anotherdir/pythonsrc && python.exe mymodule.py
On unix
PYTHONPATH=/somedir/pythonsrc:/anotherdir/pythonsrc python mymodule.py
answered Apr 6, 2012 at 13:55
Cédric Julien
81.2k16 gold badges131 silver badges134 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Josh Lee
You can use
PYTHONPATH=... python mymodule.py to set the variable just for that invocation.Start a new shell using /C option.
cmd.exe /C "set PYTHONPATH=/somedir/pythonsrc && python.exe mymoudle.py"
answered Apr 6, 2012 at 14:03
Alexander
23.5k11 gold badges65 silver badges74 bronze badges
Comments
lang-py
set PYTHONPATH=...?PYTHONPATHs explicitly, because my "general" PYTHONPATH includes a relative path (.-- always nice to have, but may interfere with other libs) but they are executed in different directories. However, it's still not possible to do.