python - Pytesseract TesseractNotFoundError [Python 3]
问题描述
使用 pytesseract 时出现错误。我通过 pip install 安装了它。
代码:
import pytesseract
from PIL import Image
img = Image.open('frame_0000.png')
x = pytesseract.image_to_string(Image.open('frame_0000.png'))
错误发生在最后一行。(x = ...)
结果:
回溯(最近一次调用最后):文件“C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py”,第 194 行,在 run_and_get_output run_tesseract(**kwargs ) 文件“C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py”,第 165 行,在 run_tesseract proc = subprocess.Popen(command, **subprocess_args( )) 文件“C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py”,第 707 行,在init restore_signals,start_new_session 中)文件“C:\Users\Artur\AppData\Local\ Programs\Python\Python36\lib\subprocess.py",第 990 行,在 _execute_child startupinfo) FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
在处理上述异常的过程中,又出现了一个异常:
回溯(最后一次调用):文件“C:\Users\Artur\Desktop\Pytesseract_test.py”,第 6 行,在 x = pytesseract.image_to_string(Image.open('frame_0000.png')) 文件“C:\ Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py",第 286 行,在 image_to_string 返回 run_and_get_output(image, 'txt', lang, config, nice) 文件“C :\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 201, in run_and_get_output raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's不在你的路上
我正在尝试运行一种解决方法,但我的经验不足使我无法正确实施:
tessdata_dir_config = '--tessdata-dir "<replace_with_your_tessdata_dir_path>"'
# Example config: '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
# It's important to include double quotes around the dir path.
pytesseract.image_to_string(image, lang='chi_sim', config=tessdata_dir_config)
有人可以帮我解决这个问题吗?我没有得到在线提供的解决方案。
解决方案
对于其他有此问题的人
我不得不进入 pytesseract.py 文件并将我的:更改
tesseract_cmd = 'tesseract'
为:
tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
免责声明:这样做
pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
并没有解决问题
推荐阅读
- php - Laravel 多态关系 - 返回关系
- javascript - 制作单选框多选JS
- swift - 即使 if 语句贯穿它,变量也不会在 if 语句中发生变化
- javascript - 如何根据用户性别显示两个不同的 image.png?
- haskell - 如何存储和引用递归函数的中间值
- oracle - 在参数中引用 Oracle 触发器新旧变量到 Oracle 存储过程
- excel - 第二次更改(ByVal 目标作为范围)不起作用
- node.js - Bearer 令牌可以验证来自 MS Teams 的消息扩展请求吗?
- windows - 电子应用程序将网络摄像头流式传输到 RTMP 服务器?
- php - Y 轴上的时间线,带有 chart.js