install.bat: make OCR setup work on Win10 and Win11

tesserocr (conda DLLs + bundled wheel) is the primary OCR backend and works
identically on both platforms. pytesseract is an optional fallback that needs
a working tesseract.exe, which winget can install on Win11 but not reliably
on Win10.

Changes:
- Winget step: reframed as optional/best-effort; failure is informational only,
  not a warning that "OCR will not work" (tesserocr handles all OCR)
- Remove pytesseract from the verification loop — it is not in requirements.txt
  and would always fail on Win10 without winget; adding it in the previous commit
  was wrong
- Remove pytesseract-specific smoke test block
- Add tesserocr end-to-end smoke test after the verification loop: opens a
  PyTessBaseAPI against the real tessdata model so DLL resolution + tessdata
  access are both exercised; sets ALL_OK=0 on failure so the installer reports
  the right thing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
alexpolo1
2026-06-19 21:10:33 +02:00
parent 63d0a334cb
commit e712076f08

View File

@@ -178,20 +178,21 @@ if exist "%BOTTY_ENV_DIR%\Library\bin\tesseract.exe" (
echo Renamed broken conda tesseract.exe
)
:: Install working tesseract 5.5.0 via winget (conda version crashes)
:: Install winget tesseract as optional pytesseract fallback.
:: tesserocr (conda DLLs + bundled wheel) is the primary OCR backend and works
:: on both Win10 and Win11 without this step. winget is not guaranteed on Win10
:: so this is best-effort only — the bot runs fine without it.
if not exist "C:\Program Files\Tesseract-OCR\tesseract.exe" (
echo Installing tesseract-OCR via winget...
echo Installing tesseract-OCR via winget ^(optional pytesseract fallback^)...
winget install --id tesseract-ocr.tesseract --silent --accept-package-agreements --accept-source-agreements 2>nul
if %errorlevel% neq 0 (
echo WARNING: winget tesseract install failed. pytesseract may not work.
echo winget not available or install failed -- skipping ^(tesserocr unaffected^)
)
)
if exist "C:\Program Files\Tesseract-OCR\tesseract.exe" (
echo Tesseract OCR found: C:\Program Files\Tesseract-OCR\tesseract.exe
echo Tesseract exe found -- pytesseract fallback is available
) else (
echo WARNING: Tesseract OCR not found after install attempt.
echo pytesseract gem-count OCR will not work until Tesseract is installed.
echo Download manually from: https://github.com/tesseract-ocr/tesseract/releases
echo Tesseract exe not found -- pytesseract fallback inactive ^(tesserocr is primary^)
)
:: Ensure tesseract.dll exists (conda may name it tesseract41.dll)
@@ -225,17 +226,6 @@ if exist "dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl" (
exit /b 1
)
:: Verify pytesseract can locate and call the winget tesseract binary.
:: ocr.py reads PYTESSERACT_TESSERACT_CMD at import time (Bug 14 fix), so no
:: source-patching is needed — we just confirm the chain works end-to-end here.
echo.
echo Verifying pytesseract OCR...
"%CONDA_EXE%" run -n botty python -c "import pytesseract, os; cmd=r'C:\Program Files\Tesseract-OCR\tesseract.exe'; pytesseract.pytesseract.tesseract_cmd=cmd; v=pytesseract.get_tesseract_version(); print(' pytesseract OK: tesseract ' + str(v))" 2>nul
if %errorlevel% neq 0 (
echo WARNING: pytesseract could not call tesseract. Gem-count OCR will not work.
echo Ensure C:\Program Files\Tesseract-OCR\tesseract.exe exists ^(run as admin^).
)
:: 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"
@@ -243,7 +233,7 @@ set "TESS_PATH=%BOTTY_ENV_DIR%\Library\bin;%BOTTY_ENV_DIR%\Library\lib;%BOTTY_EN
echo.
echo Verifying all dependencies...
set "ALL_OK=1"
for %%M in (cv2 mss numpy tesserocr pytesseract discord transitions rapidfuzz) do (
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 (
@@ -254,6 +244,18 @@ for %%M in (cv2 mss numpy tesserocr pytesseract discord transitions rapidfuzz) d
)
)
:: Smoke-test tesserocr end-to-end: DLL load + tessdata access.
echo.
echo Smoke-testing tesserocr OCR...
set "PATH=%TESS_PATH%;%PATH%"
"%CONDA_EXE%" run -n botty python -c "import sys; sys.path.insert(0,'src'); import os; os.add_dll_directory(r'%BOTTY_ENV_DIR%\Library\bin'); from tesserocr import PyTessBaseAPI, OEM; api=PyTessBaseAPI(psm=7,oem=OEM.LSTM_ONLY,path='assets/tessdata',lang='hover-eng_inconsolata_inv_th_fast'); api.End(); print(' tesserocr OK')" 2>nul
if %errorlevel% neq 0 (
echo FAILED: tesserocr could not open tessdata model.
echo Item hover OCR and gem-count OCR will not work.
echo Check that conda tesseract DLLs and bundled wheel installed correctly above.
set "ALL_OK=0"
)
if "%ALL_OK%"=="1" (
echo.
echo All dependencies verified.