Reputation: 6538
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?
Upvotes: 6
Views: 9690
Reputation: 1
It works for me by adding "delims="
value to the /f
option under the for
command:
@ECHO OFF
for /f "delims=" %%p in ('where python') do SET PYTHONPATH=%%p
ECHO %PYTHONPATH%
The result:
C:\TEMP>pypathtest.bat
C:\Program Files (x86)\Python38-32\python.exe
Upvotes: 0
Reputation: 342
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.
Upvotes: 0
Reputation: 2967
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%
Upvotes: 8