首页 > 解决方案 > 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)

有人可以帮我解决这个问题吗?我没有得到在线提供的解决方案。

标签: pythontesseract

解决方案


对于其他有此问题的人

我不得不进入 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'
并没有解决问题


推荐阅读