python - 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 应用程序,但无济于事。
解决方案
我看到步骤分散在不同的答案中。根据我最近在 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'
推荐阅读
- python - 有没有办法让不和谐的 py 机器人通过命令停止 cog 中的循环实例
- jpa - 如何强制关系数据库的@Lock注释异常
- java - 使用“external.properties”文件作为通用文件
- multidimensional-array - 如何从数组中删除双坐标以及这些双坐标之间的所有坐标
- node.js - 使用 NodeJS 将灯塔指标发送到 Graphite
- rest - 无法初始化类 org.codehaus.groovy.vmplugin.v7.Java7
- javascript - 通过 id 或类阅读更多阅读更少的 javascript
- jupyter-notebook - 在 Voila 中运行的 Jupyter 笔记本,检测内核
- business-objects - 标识符为“26”的“报表元素”类型的资源不存在
- javascript - 如何确定特定节点何时在 DOM 中发生了变异?