Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Python location using Windows batch file?

I need to create a windows batch script which creates and moves one specific file to PYTHONPATH\Lib\distutils folder.

Here is what I am attempting to do:

ECHO [build] >> distutils.cfg
ECHO compiler=mingw32 >> distutils.cfg
MOVE distutils.cfg PYTHONPATH\Lib\distutils

However, PYTHONPATH does not exist but I know that Python location is set in PATH which I can check. How can I parse PATH and extract Python location from it?

like image 502
minerals Avatar asked Dec 05 '22 19:12

minerals


2 Answers

Since python is in your PATH you can use function where, which is a Windows analogue of Linux whereis function:

> where python.exe

See details here. You can set output of where command to a variable and then use it (see this post).

like image 131
vrs Avatar answered Dec 11 '22 08:12

vrs


If you have only one python instance, you can try this:

@ECHO OFF
FOR /f %%p in ('where python') do SET PYTHONPATH=%%p
ECHO %PYTHONPATH%
like image 26
ashwinjv Avatar answered Dec 11 '22 09:12

ashwinjv