我正在尝试在 Python 中使用 pytesseract,但我总是遇到以下错误:
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
但是,pytesseract 和 Tesseract 安装在我的系统上。
产生此错误的示例代码:
import cv2
import pytesseract
img = cv2.imread('1d.png')
print(pytesseract.image_to_string(img))
如何解决这个 TesseractNotFoundError?
最佳答案
我收到此错误是因为我使用 pip
安装了 pytesseract
但忘记安装二进制文件。
在 Linux 上
sudo apt update
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
在 Mac 上
brew install tesseract
在 Windows 上
从 https://github.com/UB-Mannheim/tesseract/wiki 下载二进制文件.然后将 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
添加到您的脚本中。 (必要时替换 tesseract 二进制文件的路径)
引用: https://pypi.org/project/pytesseract/ (安装部分)和 https://github.com/tesseract-ocr/tesseract/wiki#installation
关于python - 如何解决 TesseractNotFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50655738/