Pytesseract TesseractNotFoundError[Python 3]

2024-09-27 07:35:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用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=…)

结果:

Traceback (most recent call last): File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_and_get_output run_tesseract(**kwargs) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 165, in run_tesseract proc = subprocess.Popen(command, **subprocess_args()) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in init restore_signals, start_new_session) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child startupinfo) FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Artur\Desktop\Pytesseract_test.py", line 6, in x = pytesseract.image_to_string(Image.open('frame_0000.png')) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 286, in image_to_string return run_and_get_output(image, 'txt', lang, config, nice) File "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 not in your path

我正试图找到一个解决办法,但我缺乏经验,无法正确实施:

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)

有人能帮我解决这个问题吗?我无法在网上找到解决方案。


Tags: inpyimageliblocaldirlineusers
3条回答

~对于其他人来说,如果他们仍然遇到这个问题,并且是一个初级程序员(就像我自己认为的那样)

对于Mac OS

尝试查找tesseract.exe的位置-如果使用 在您的终端上使用brew

>brew list tesseract

这应该列出tesseract.exe的位置,大致类似于

> /usr/local/Cellar/tesseract/3.05.02/bin/tesseract

Then following their instructions

pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'

应该做的把戏!

出现此错误的原因是代码是使用python3编译的,但模块是使用pip
因此pytesseract模块被安装到Python2而不是Python3。
使用pip3安装可以解决这个问题。

对于其他有这个问题的人

I had to go into the pytesseract.py file and changed my:
tesseract_cmd = 'tesseract'
To:
tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'

免责声明:执行
pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
没有解决问题

相关问题 更多 >

    热门问题