Files
my-botty/install.bat

186 lines
6.0 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
:: Always run from the folder this script lives in
cd /d "%~dp0"
echo ============================================
echo Botty - Dependency Installer
echo ============================================
echo.
:: --- Detect Windows version ---
for /f "tokens=3" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild 2^>nul') do set "WIN_BUILD=%%A"
if not defined WIN_BUILD (
echo WARNING: Could not detect Windows build number.
set "WIN_BUILD=0"
)
echo Detected Windows build: %WIN_BUILD%
set /a "WIN_BUILD_NUM=%WIN_BUILD%" 2>nul || set "WIN_BUILD_NUM=0"
if %WIN_BUILD_NUM% GEQ 22000 (
echo Detected Windows 11 — using relative mouse mode (no ABSOLUTE flag)
set "WIN11=1"
set "REQ_FILE=requirements-win11.txt"
set "ENV_FILE=environment-win11.yml"
) else (
echo Detected Windows 10 or earlier — using absolute mouse mode
set "WIN11=0"
set "REQ_FILE=requirements-win10.txt"
set "ENV_FILE=environment-win10.yml"
)
if not exist "%REQ_FILE%" set "REQ_FILE=requirements.txt"
if not exist "%ENV_FILE%" set "ENV_FILE=environment.yml"
echo Requirements profile: %REQ_FILE%
echo Environment profile: %ENV_FILE%
echo.
:: --- Find conda ---
set "CONDA_EXE="
for %%C in (
"%USERPROFILE%\miniforge3\Scripts\conda.exe"
"%USERPROFILE%\miniconda3\Scripts\conda.exe"
"%USERPROFILE%\anaconda3\Scripts\conda.exe"
"%ProgramData%\miniforge3\Scripts\conda.exe"
"%ProgramData%\miniconda3\Scripts\conda.exe"
"%ProgramData%\anaconda3\Scripts\conda.exe"
) do (
if exist %%C (
set "CONDA_EXE=%%~C"
goto :found_conda
)
)
echo ERROR: conda not found. Install Miniforge or Miniconda first:
echo https://github.com/conda-forge/miniforge/releases/latest
echo.
pause
exit /b 1
:found_conda
echo Found conda: %CONDA_EXE%
echo.
:: --- Test conda works (catches broken base env, missing pywin32, etc.) ---
echo Testing conda...
"%CONDA_EXE%" --version >nul 2>&1
if %errorlevel% neq 0 (
echo.
echo ERROR: conda found but failed to run. Your conda installation may be broken.
echo Try re-installing Miniforge: https://github.com/conda-forge/miniforge
echo.
pause
exit /b 1
)
echo conda is working.
echo.
:: --- Create or update the botty env ---
"%CONDA_EXE%" env list | findstr /C:"botty" >nul 2>&1
if %errorlevel% equ 0 (
echo Updating existing 'botty' conda environment...
"%CONDA_EXE%" env update -f "%ENV_FILE%" --prune
) else (
echo Creating 'botty' conda environment...
"%CONDA_EXE%" env create -f "%ENV_FILE%"
)
if %errorlevel% neq 0 (
echo.
echo ERROR: conda env create/update failed. See output above.
pause
exit /b 1
)
:: --- Verify botty env has Python ---
set "PYTHON="
for %%C in (
"%USERPROFILE%\miniforge3\envs\botty\python.exe"
"%USERPROFILE%\miniconda3\envs\botty\python.exe"
"%USERPROFILE%\anaconda3\envs\botty\python.exe"
"%ProgramData%\miniforge3\envs\botty\python.exe"
"%ProgramData%\miniconda3\envs\botty\python.exe"
"%ProgramData%\anaconda3\envs\botty\python.exe"
) do (
if exist %%C (
set "PYTHON=%%~C"
goto :env_created
)
)
echo.
echo ERROR: botty env was created but python.exe was not found.
echo This usually means the env build failed. Check output above.
pause
exit /b 1
:env_created
echo Botty Python: %PYTHON%
:: --- Install OS-specific pip requirements profile ---
echo.
echo Installing Botty requirements from %REQ_FILE%...
"%CONDA_EXE%" run -n botty python -m pip install -r "%REQ_FILE%"
if %errorlevel% neq 0 (
echo.
echo ERROR: pip requirements install failed for %REQ_FILE%.
pause
exit /b 1
)
echo.
echo Botty osdetect:
"%CONDA_EXE%" run -n botty python -c "import sys; sys.path.insert(0, 'src'); from utils.os_detect import describe_current_os; print(describe_current_os())"
:: --- Remove old pip-installed tesserocr wheel if present (we may reinstall from bundled wheel below) ---
echo.
echo Removing old pip-installed tesserocr if present...
"%PYTHON%" -m pip uninstall tesserocr -y >nul 2>&1
:: --- Smoke test via conda run (activates the full env like "conda activate botty") ---
:: This is the only reliable way to ensure all DLL transitive deps are resolved.
echo.
echo Verifying dependencies...
"%CONDA_EXE%" run -n botty python -c "import cv2,mss,numpy,tesserocr,discord,transitions,rapidfuzz" >nul 2>&1
if %errorlevel% neq 0 (
echo.
echo WARNING: Dependency check failed. Running diagnostics...
echo.
"%CONDA_EXE%" run -n botty python -c "import tesserocr; print(' tesserocr: OK')" 2>&1
if %errorlevel% neq 0 (
echo.
echo tesserocr is missing from conda environment. Trying bundled wheel fallback...
if exist "dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl" (
"%CONDA_EXE%" run -n botty python -m pip install --force-reinstall --no-deps "dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl"
if %errorlevel% neq 0 (
echo.
echo ERROR: Bundled tesserocr wheel install failed.
) else (
echo Bundled tesserocr wheel installed, re-checking imports...
"%CONDA_EXE%" run -n botty python -c "import cv2,mss,numpy,tesserocr,discord,transitions,rapidfuzz" >nul 2>&1
if %errorlevel% equ 0 (
echo All key dependencies verified after wheel fallback.
goto :install_done
)
)
) else (
echo.
echo ERROR: Missing fallback wheel:
echo dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl
)
)
echo.
echo *** Do NOT run "pip install tesserocr" manually - it builds from source and
echo *** will usually fail on Windows. Re-run install.bat to fix dependencies.
) else (
echo All key dependencies verified.
)
:install_done
echo.
echo ============================================
echo Installation complete!
echo Run botty with: run_botty.bat
echo ============================================
echo.
pause