pythonbatch-filepathpythonpath

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?


Solution

  • 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).