fix(install): permanent fix for tesserocr DLL load failure

tesserocr never loaded -- install.bat always reported "tesserocr: not
available (DLL issue)" and the bot ran on the pytesseract fallback, which
shells out to tesseract.exe per OCR call instead of using the in-process
C++ API.

Root cause, found by walking the import table with pefile:
  tesserocr.pyd -> tesseract52.dll -> leptonica-1.78.0.dll -> tiff.dll
  -> libdeflate.dll  <- MISSING
Current conda-forge libdeflate (>=1.20) installs the library as
"deflate.dll", but the older tiff.dll from the tesseract=4.x stack still
imports the previous name "libdeflate.dll". Nothing provided that name, so
tiff.dll failed to load and every DLL above it failed with WinError 126
("The specified module could not be found") -- which is why the error
looked like a missing module even though every file was present.

Fix: install libdeflate explicitly alongside tesseract=4.*, then copy
deflate.dll to the legacy name libdeflate.dll when that name is absent.
Same library, same exports.

Verified: removing the alias reproduces the failure exactly; running
install.bat recreates it and the installer now reports "tesserocr: OK
(fast path)". tesserocr initialises and performs real OCR with both bundled
models, and the bot logs "OCR backend: tesserocr (primary)" at startup.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
alexpolo1
2026-08-06 18:59:31 +02:00
parent b627172f1e
commit 7fd0555468

View File

@@ -298,8 +298,27 @@ set "TESS_PATH=%BOTTY_ENV_DIR%\Library\bin;%BOTTY_ENV_DIR%\Library\lib;%BOTTY_EN
:: Remove any existing pip/wheel tesserocr
"%PYTHON%" -m pip uninstall tesserocr -y >nul 2>&1
:: conda tesseract 4.x provides leptonica-1.78.0.dll (MSVC) which tesseract52.dll needs
"%CONDA_EXE%" install -n botty "tesseract=4.*" -c conda-forge -y >nul 2>&1
:: conda tesseract 4.x provides leptonica-1.78.0.dll (MSVC) which tesseract52.dll needs.
:: libdeflate is required explicitly: the libtiff that ships with tesseract 4.x
:: imports libdeflate, and without it the whole chain below fails to load.
"%CONDA_EXE%" install -n botty "tesseract=4.*" libdeflate -c conda-forge -y >nul 2>&1
:: libdeflate.dll compatibility alias.
:: THIS IS WHAT MAKES tesserocr WORK. The DLL chain is:
:: tesserocr.pyd -> tesseract52.dll -> leptonica-1.78.0.dll -> tiff.dll -> libdeflate.dll
:: Current conda-forge libdeflate (>=1.20) installs the library as "deflate.dll",
:: but the older tiff.dll from the tesseract=4.x stack still imports the previous
:: name "libdeflate.dll". Nothing provides that name, so tiff.dll fails to load,
:: and every DLL above it in the chain fails with WinError 126 ("The specified
:: module could not be found") -- which surfaced as tesserocr being permanently
:: unavailable and the bot silently falling back to the slower pytesseract.
:: Copying deflate.dll to the old name satisfies the import; the exported symbols
:: are the same library, verified by tesserocr initialising and running real OCR.
if not exist "%BOTTY_ENV_DIR%\Library\bin\libdeflate.dll" (
if exist "%BOTTY_ENV_DIR%\Library\bin\deflate.dll" (
copy /y "%BOTTY_ENV_DIR%\Library\bin\deflate.dll" "%BOTTY_ENV_DIR%\Library\bin\libdeflate.dll" >nul
)
)
:: conda tesseract.exe crashes on Win10 and Win11 — disable it, keep the DLLs
if exist "%BOTTY_ENV_DIR%\Library\bin\tesseract.exe" (