fix: patch pytesseract to handle tesseract --version crashes
This commit is contained in:
32
install.bat
32
install.bat
@@ -203,6 +203,38 @@ 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')
|
||||
"
|
||||
|
||||
:: 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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user