首页 > 解决方案 > Pytesseract:“TesseractNotFound 错误:tesseract 未安装或不在您的路径中”,我该如何解决?

问题描述

我正在尝试在 python 中运行一个基本且非常简单的代码。

from PIL import Image
import pytesseract

im = Image.open("sample1.jpg")

text = pytesseract.image_to_string(im, lang = 'eng')

print(text)

这就是它的样子,我实际上已经通过安装程序安装了 tesseract for windows。我对 Python 很陌生,我不确定如何继续?

这里的任何指导都会非常有帮助。我尝试重新启动我的 Spyder 应用程序,但无济于事。

标签: pythontesseract

解决方案


我看到步骤分散在不同的答案中。根据我最近在 Windows 上遇到此 pytesseract 错误的经验,依次编写不同的步骤以更轻松地解决错误:

1 . 使用 Windows 安装程序安装 tesseract:https ://github.com/UB-Mannheim/tesseract/wiki

2 . 请注意安装中的 tesseract 路径。此编辑时的默认安装路径是:C:\Users\USER\AppData\Local\Tesseract-OCR. 它可能会改变,所以请检查安装路径。

3 .pip install pytesseract

4 . 在调用之前在脚本中设置 tesseract 路径image_to_string

pytesseract.pytesseract.tesseract_cmd = r'C:\Users\USER\AppData\Local\Tesseract-OCR\tesseract.exe'


推荐阅读