我正在尝试在 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 应用程序,但无济于事。
原文由 Jed Bartlet 发布,翻译遵循 CC BY-SA 4.0 许可协议
我看到步骤分散在不同的答案中。根据我最近在 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 .在调用
image_to_string
之前在脚本中设置 tesseract 路径:pytesseract.pytesseract.tesseract_cmd = r'C:\Users\USER\AppData\Local\Tesseract-OCR\tesseract.exe'