install.bat: fix OCR setup — verify tesseract exe, drop broken patch, add pytesseract check

Three fixes:
1. After winget tesseract install, check C:\Program Files\Tesseract-OCR\tesseract.exe
   actually exists and print a download link if not — previously silent failure.
2. Remove the broken pytesseract source-patch block (Python syntax error on the
   os.path.join call — it has never run). ocr.py already handles cmd discovery at
   import time via PYTESSERACT_TESSERACT_CMD (Bug 14 fix), so patching is moot.
   Replace with a pytesseract.get_tesseract_version() smoke test that exercises the
   full exe chain and fails clearly if tesseract is missing.
3. Add pytesseract to the dependency verification loop alongside tesserocr.

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

View File

@@ -186,6 +186,13 @@ if not exist "C:\Program Files\Tesseract-OCR\tesseract.exe" (
echo WARNING: winget tesseract install failed. pytesseract may not work.
)
)
if exist "C:\Program Files\Tesseract-OCR\tesseract.exe" (
echo Tesseract OCR found: C:\Program Files\Tesseract-OCR\tesseract.exe
) 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
)
:: Ensure tesseract.dll exists (conda may name it tesseract41.dll)
if not exist "%BOTTY_ENV_DIR%\Library\bin\tesseract.dll" (
@@ -218,37 +225,16 @@ if exist "dependencies\tesserocr-2.5.2-cp310-cp310-win_amd64.whl" (
exit /b 1
)
:: Patch pytesseract to handle tesseract --version crashes (access violation on some systems)
echo Patching pytesseract...
"%PYTHON%" -c "
import os
f = os.path.join(os.path.dirname(__import__('pathlib').Path(__import__('site').getsitepackages()[0]).parent, 'pytesseract', 'pytesseract.py')
for p in __import__('site').getsitepackages():
fp = os.path.join(p, 'pytesseract', 'pytesseract.py')
if os.path.exists(fp):
f = fp
break
if os.path.exists(f):
with open(f, 'r') as fh:
content = fh.read()
if 'subprocess.CalledProcessError' not in content:
old = ''' except OSError:
raise TesseractNotFoundError()'''
new = ''' except OSError:
raise TesseractNotFoundError()
except subprocess.CalledProcessError:
import warnings
warnings.warn('tesseract --version failed, skipping version check')
return None'''
content = content.replace(old, new)
with open(f, 'w') as fh:
fh.write(content)
print(' pytesseract patched')
else:
print(' pytesseract already patched')
else:
print(' pytesseract not found')
"
:: 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"
@@ -257,7 +243,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 discord transitions rapidfuzz) do (
for %%M in (cv2 mss numpy tesserocr pytesseract 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 (