Vinit Dhatrak
Vinit Dhatrak

Reputation: 7054

Python path in environment

I want to call a python script from batch script, but I dont want to hard-code path to python executable (python.exe) in my calling script.

e.g.

c:\python26\python.exe test.py

$PYTHONPATH\python.exe test.py

Is there any way to have PYTHONPATH like setting ?

Upvotes: 0

Views: 2724

Answers (3)

monojohnny
monojohnny

Reputation: 6201

set PYTHON_INSTALL=D:\python26

then:

%PYTHON_INSTALL%\python.exe test.py

You could set up the PYTHON_INSTALL var using My Computer | Advanced | Environment Variables if you want it to persist.

EDIT: And building on the other post (put the path to Python in the system path), you could have the best of both worlds:

set PATH=%PATH%;%PYTHON_INSTALL%

Then you can just call:

python test.py

EDIT 2:

Renamed 'PYTHONPATH' to 'PYTHON_INSTALL' as another poster pointed out that the environment variable 'PYTHONPATH' already has a defined use.

Upvotes: 3

YOU
YOU

Reputation: 123937

Try

set PYTHONPATH=c:\python26
%PYTHONPATH%\python.exe test.py

Or

set PATH=%PATH%;C:\python26;
python test.py

Note: environment variable PYTHONPATH has different purpose for searching python modules/extensions, So should not be shadowed.

PYTHONPATH   : ';'-separated list of directories prefixed to the
               default module search path.  The result is sys.path.

Upvotes: 0

Ned Batchelder
Ned Batchelder

Reputation: 376052

The simplest thing is to add c:\python26 to you system's PATH.

Also, depending on how you installed Python, you should be able to just use test.py on the command line.

Upvotes: 4

Related Questions