237 lines
6.7 KiB
Batchfile
237 lines
6.7 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 ---
|
|
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.
|
|
|
|
:: --- Find botty 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 :check_env
|
|
)
|
|
)
|
|
|
|
:: --- Create botty env ---
|
|
echo Creating 'botty' conda environment...
|
|
"%CONDA_EXE%" env create -f "%ENV_FILE%"
|
|
if %errorlevel% neq 0 (
|
|
echo.
|
|
echo ERROR: conda env create failed. See output above.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
:check_env
|
|
:: Re-scan for Python after env creation
|
|
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_ready
|
|
)
|
|
)
|
|
|
|
echo.
|
|
echo ERROR: botty env was created but python.exe was not found.
|
|
pause
|
|
exit /b 1
|
|
|
|
:env_ready
|
|
echo Botty Python: %PYTHON%
|
|
|
|
:: --- Install pip requirements ---
|
|
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())"
|
|
|
|
:: --- Fix tesserocr ---
|
|
echo.
|
|
echo Setting up tesserocr...
|
|
|
|
:: Uninstall any pip tesserocr (conda-forge build fails on Windows)
|
|
"%PYTHON%" -m pip uninstall tesserocr -y >nul 2>&1
|
|
|
|
:: Find the botty env directory
|
|
set "BOTTY_ENV_DIR="
|
|
for %%C in (
|
|
"%USERPROFILE%\miniforge3\envs\botty"
|
|
"%USERPROFILE%\miniconda3\envs\botty"
|
|
"%USERPROFILE%\anaconda3\envs\botty"
|
|
"%ProgramData%\miniforge3\envs\botty"
|
|
"%ProgramData%\miniconda3\envs\botty"
|
|
"%ProgramData%\anaconda3\envs\botty"
|
|
) do (
|
|
if exist %%C (
|
|
set "BOTTY_ENV_DIR=%%~C"
|
|
goto :env_found
|
|
)
|
|
)
|
|
echo ERROR: Could not find botty env directory.
|
|
pause
|
|
exit /b 1
|
|
|
|
:env_found
|
|
|
|
:: Install tesseract 4.x from conda (bundled wheel needs tesseract.dll not tesseract52.dll)
|
|
echo Installing tesseract 4.x...
|
|
"%CONDA_EXE%" install -n botty "tesseract=4.*" -c conda-forge -y --force-reinstall >nul 2>&1
|
|
|
|
:: Ensure tesseract.dll exists (conda may name it tesseract41.dll)
|
|
if not exist "%BOTTY_ENV_DIR%\Library\bin\tesseract.dll" (
|
|
if exist "%BOTTY_ENV_DIR%\Library\bin\tesseract41.dll" (
|
|
copy /y "%BOTTY_ENV_DIR%\Library\bin\tesseract41.dll" "%BOTTY_ENV_DIR%\Library\bin\tesseract.dll" >nul
|
|
echo Created tesseract.dll symlink from tesseract41.dll
|
|
)
|
|
)
|
|
|
|
:: Install bundled tesserocr wheel
|
|
if exist "dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl" (
|
|
echo Installing bundled tesserocr wheel...
|
|
"%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 ERROR: Bundled tesserocr wheel install failed.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
echo tesserocr wheel installed.
|
|
) else (
|
|
echo ERROR: Missing bundled wheel: dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
:: Set PATH for tesseract DLL before testing
|
|
set "TESS_PATH=%BOTTY_ENV_DIR%\Library\bin;%BOTTY_ENV_DIR%\Library\lib;%BOTTY_ENV_DIR%\DLLs;%BOTTY_ENV_DIR%\Scripts"
|
|
|
|
:: --- Verify all dependencies ---
|
|
echo.
|
|
echo Verifying all dependencies...
|
|
set "ALL_OK=1"
|
|
for %%M in (cv2 mss numpy tesserocr discord transitions rapidfuzz) do (
|
|
set "PATH=%TESS_PATH%;%PATH%"
|
|
"%CONDA_EXE%" run -n botty python -c "import %%M" >nul 2>&1
|
|
if %errorlevel% neq 0 (
|
|
echo FAILED: %%M
|
|
set "ALL_OK=0"
|
|
) else (
|
|
echo %%M: OK
|
|
)
|
|
)
|
|
|
|
if "%ALL_OK%"=="1" (
|
|
echo.
|
|
echo All dependencies verified.
|
|
) else (
|
|
echo.
|
|
echo WARNING: Some dependencies failed above.
|
|
echo This is often a PATH issue. Try running from a fresh CMD/PowerShell:
|
|
echo conda activate botty
|
|
echo python -c "import tesserocr"
|
|
echo.
|
|
)
|
|
|
|
:install_done
|
|
echo.
|
|
echo ============================================
|
|
echo Installation complete!
|
|
echo Run botty with: run_botty.bat
|
|
echo ============================================
|
|
echo.
|
|
pause
|