Files
md_to_gost/build-find-python311.bat
T
Igor20264 510f7e7adf
Python application / build (push) Waiting to run
v0.5.2
Что то сделал
2026-09-08 19:37:54 +03:00

91 lines
2.8 KiB
Batchfile

@echo off
REM Вызывается через call из build-exe.bat / build-exe-fast.bat.
REM На успехе: PYEXE = полный путь к python.exe 3.11, errorlevel 0.
REM Если 3.11 нет: PYEXE пустой, errorlevel 1.
set "PYEXE="
where py >nul 2>&1
if not errorlevel 1 (
for /f "delims=" %%I in ('py -3.11 -c "import sys; print(sys.executable)" 2^>nul ^| findstr /i /c:"python.exe"') do call :consider "%%I"
)
if defined PYEXE goto :ok
where uv >nul 2>&1
if not errorlevel 1 (
for /f "delims=" %%I in ('uv python find 3.11 2^>nul') do call :consider "%%I"
)
if defined PYEXE goto :ok
where python3.11 >nul 2>&1
if not errorlevel 1 (
for /f "delims=" %%I in ('where python3.11 2^>nul') do call :consider "%%I"
)
if defined PYEXE goto :ok
where python >nul 2>&1
if not errorlevel 1 (
for /f "delims=" %%I in ('where python 2^>nul') do call :consider "%%I"
)
if defined PYEXE goto :ok
where python3 >nul 2>&1
if not errorlevel 1 (
for /f "delims=" %%I in ('where python3 2^>nul') do call :consider "%%I"
)
if defined PYEXE goto :ok
if defined LOCALAPPDATA (
for /d %%D in ("%LOCALAPPDATA%\Programs\Python\Python311*") do call :consider "%%D\python.exe"
for /d %%D in ("%LOCALAPPDATA%\uv\python\cpython-3.11.*-windows*") do call :consider "%%D\python.exe"
)
if defined PYEXE goto :ok
if defined APPDATA (
for /d %%D in ("%APPDATA%\uv\python\cpython-3.11.*-windows*") do call :consider "%%D\python.exe"
)
if defined PYEXE goto :ok
if defined USERPROFILE (
for /d %%D in ("%USERPROFILE%\.local\share\uv\python\cpython-3.11.*-windows*") do call :consider "%%D\python.exe"
)
if defined PYEXE goto :ok
call :consider "%ProgramFiles%\Python311\python.exe"
if defined PYEXE goto :ok
call :consider "%ProgramFiles(x86)%\Python311-32\python.exe"
if defined PYEXE goto :ok
call :consider "C:\Python311\python.exe"
if defined PYEXE goto :ok
where uv >nul 2>&1
if errorlevel 1 goto :miss
echo Python 3.11 не найден, ставлю через uv python install 3.11 ...
uv python install 3.11
if errorlevel 1 goto :miss
for /f "delims=" %%I in ('uv python find 3.11 2^>nul') do call :consider "%%I"
if defined PYEXE goto :ok
:miss
echo Python 3.11 не найден.
echo Поставьте CPython 3.11 ^(python.org / py -3.11^) либо uv ^(тогда: uv python install 3.11^).
echo Либо соберите через build-exe-uvx.bat — uvx сам подтянет 3.11.
set "PYEXE="
exit /b 1
:ok
echo Python 3.11: %PYEXE%
"%PYEXE%" --version
exit /b 0
:consider
if defined PYEXE goto :eof
if "%~1"=="" goto :eof
echo "%~1" | findstr /i "WindowsApps" >nul
if not errorlevel 1 goto :eof
if not exist "%~1" goto :eof
"%~1" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 11) else 1)" 1>nul 2>nul
if errorlevel 1 goto :eof
set "PYEXE=%~1"
goto :eof