File size: 2,222 Bytes
67fe962 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | @echo off
rem Sets PY to a Python 3.10+ command, offering to install Python 3.12 with winget when none is found.
rem Used by setup.bat and start.bat: call find_python.bat then if not defined PY exit /b 1
set "PY="
set "CHECK=import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)"
rem 1) the py launcher, 2) python on PATH (the Microsoft Store alias fails this check, it is not a real Python),
rem 3) the per-user install locations winget / python.org use
if not defined ONW_TEST_NOPY (
py -3 -c "%CHECK%" >nul 2>nul && set "PY=py -3"
if not defined PY python -c "%CHECK%" >nul 2>nul && set "PY=python"
if not defined PY for %%V in (313 312 311 310) do (
if not defined PY if exist "%LOCALAPPDATA%\Programs\Python\Python%%V\python.exe" set "PY="%LOCALAPPDATA%\Programs\Python\Python%%V\python.exe""
)
)
if defined PY exit /b 0
echo.
echo Python 3.10 or newer was not found.
where winget >nul 2>nul
if errorlevel 1 (
echo winget is not available either. Please install Python from https://www.python.org/downloads/
echo ^(check "Add python.exe to PATH"^), then run this again.
start "" https://www.python.org/downloads/
exit /b 1
)
choice /c YN /m "Install Python 3.12 for this user with winget now (accepts the Python license)"
if errorlevel 2 (
echo Please install Python 3.10+ from https://www.python.org/downloads/ and run this again.
exit /b 1
)
winget install -e --id Python.Python.3.12 --scope user --accept-package-agreements --accept-source-agreements
if errorlevel 1 (
echo winget could not install Python. Please install it from https://www.python.org/downloads/
exit /b 1
)
rem the new PATH is not visible in this window yet: use the installed files directly
if exist "%LOCALAPPDATA%\Programs\Python\Python312\python.exe" set "PY="%LOCALAPPDATA%\Programs\Python\Python312\python.exe""
if not defined PY if exist "%LOCALAPPDATA%\Programs\Python\Launcher\py.exe" set "PY="%LOCALAPPDATA%\Programs\Python\Launcher\py.exe" -3"
if not defined PY (
echo Python was installed but could not be found yet. Please open a new window and run this again.
exit /b 1
)
echo [setup] using %PY%
exit /b 0
|