Find Python after installing it, like Git and Node
winget installed Python successfully and the very next line reported it missing. The re-probe only checked `py -3` and `python` on PATH, and a just-installed interpreter is not on the PATH this session inherited at start — the same failure Git and Node already had directory probes for. Python never got them. Probe the standard install homes before giving up: %LOCALAPPDATA%\Programs\Python\Python3* (per-user, winget's default) %ProgramFiles%\Python3* (all-users) ...\Python\Launcher\py.exe, %SystemRoot%\py.exe Globbed rather than version-pinned so a 3.13 install is found too, and the loop body uses %%~D: a quoted for /d pattern carries its quotes through, which would otherwise mangle every path built from "C:\Program Files\Python312". This also covers Python installed without "Add python.exe to PATH" ticked, which is the more common way to end up here without winget involved. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
4288d8c298
commit
a0ef06d933
+19
-2
@@ -139,6 +139,19 @@ REM its major version separates a real interpreter from the stub. The py
|
||||
REM launcher is preferred when present - it is not shadowed by the stub.
|
||||
:py_probe
|
||||
set "PYCMD="
|
||||
for /f "tokens=*" %%v in ('py -3 -c "import sys;print(sys.version_info[0])" 2^>nul') do if "%%v"=="3" set "PYCMD=py -3"
|
||||
if not defined PYCMD for /f "tokens=*" %%v in ('python -c "import sys;print(sys.version_info[0])" 2^>nul') do if "%%v"=="3" set "PYCMD=python"
|
||||
if defined PYCMD goto :py_found
|
||||
|
||||
REM Not on PATH. Same story as Git and Node: a Python installed just now - or
|
||||
REM installed without "Add to PATH" ticked - is invisible to this session, which
|
||||
REM inherited its PATH at start. Prepend the standard install homes and retry.
|
||||
REM The version is globbed rather than hardcoded so a 3.13 install still works.
|
||||
for /d %%D in ("%LOCALAPPDATA%\Programs\Python\Python3*") do if exist "%%~D\python.exe" set "PATH=%%~D;%%~D\Scripts;%PATH%"
|
||||
for /d %%D in ("%ProgramFiles%\Python3*") do if exist "%%~D\python.exe" set "PATH=%%~D;%%~D\Scripts;%PATH%"
|
||||
if exist "%LOCALAPPDATA%\Programs\Python\Launcher\py.exe" set "PATH=%LOCALAPPDATA%\Programs\Python\Launcher;%PATH%"
|
||||
if exist "%SystemRoot%\py.exe" set "PATH=%SystemRoot%;%PATH%"
|
||||
|
||||
for /f "tokens=*" %%v in ('py -3 -c "import sys;print(sys.version_info[0])" 2^>nul') do if "%%v"=="3" set "PYCMD=py -3"
|
||||
if not defined PYCMD for /f "tokens=*" %%v in ('python -c "import sys;print(sys.version_info[0])" 2^>nul') do if "%%v"=="3" set "PYCMD=python"
|
||||
if defined PYCMD goto :py_found
|
||||
@@ -156,8 +169,12 @@ winget install --id Python.Python.3.12 -e --source winget --accept-source-agreem
|
||||
goto :py_probe
|
||||
|
||||
:py_skip
|
||||
echo [--] python not found - the dashboard will still work.
|
||||
echo Needed only for the clicker ^(clicker\runner.py^).
|
||||
echo [--] python not found on PATH, and not in any of:
|
||||
echo %LOCALAPPDATA%\Programs\Python\Python3*
|
||||
echo %ProgramFiles%\Python3*
|
||||
echo The dashboard will still work - python is only needed for the
|
||||
echo clicker ^(clicker\runner.py^). If you just installed it, close this
|
||||
echo window and re-run to pick up the new PATH.
|
||||
goto :py_end
|
||||
|
||||
:py_found
|
||||
|
||||
Reference in New Issue
Block a user