5

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?

minerals
  • 6,090
  • 17
  • 62
  • 107

3 Answers3

12

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

vrs
  • 1,922
  • 16
  • 23
7

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%
ashwinjv
  • 2,787
  • 1
  • 23
  • 32
0

Why search for python.exe using WHERE when you know the answer? It's in the path env var! So all you need to do is scan the %path% var. It can be done like this:

echo %path% | split ; | find /i "python"

OK, here you need the split prog, but it's easily made (in C or batch) and you need it anyway.

Henrik
  • 332
  • 3
  • 12