我已经使用安装了 pytesseract
库
pip install pytesseract
当我尝试使用 image_to_text
方法时,它给了我一个
FileNotFoundError: [WinError 2] 系统找不到指定的文件
我在谷歌上搜索了一下,发现我应该更改 pytesseract.py 文件和行中的某些内容
tesseract_cmd = 'tesseract'
应该成为
tesseract_cmd = path_to_folder_that_contains_tesseractEXE + 'tesseract'
我搜索并没有在我的 Python 文件夹中找到任何 tesseract.exe
文件,然后我重新安装了库,但文件仍然不存在。最后,我将这一行替换为:
tesseract_cmd = path_to_folder_that_contains_pytesseractEXE + 'pytesseract'
我的程序抛出:
pytesseract.pytesseract.TesseractError: (2, ‘Usage: python pytesseract.py [-l lang] input_file’)
我该怎么做才能让我的程序工作?
PS这是我的程序代码:
from pytesseract import image_to_string
from PIL import Image, ImageEnhance, ImageFilter
im = Image.open(r'C:\Users\Филипп\Desktop\ImageToText_Python\NoName.png')
print(im)
txt = image_to_string(im)
print(txt)
第一次尝试的完整追溯:
File "C:/Users/user/Desktop/ImageToText.py", line 10, in <module>
text = pytesseract.image_to_string(im)
File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in
image_to_string config=config)
File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in
run_tesseract proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Python\lib\subprocess.py", line 947, in __init__ restore_signals, start_new_session)
File "C:\Python\lib\subprocess.py", line 1224, in _execute_child startupinfo)
FileNotFoundError: [WinError 2]The system can not find the file specified
第二次尝试的完整追溯
Traceback (most recent call last):
File "C:\Users\user\Desktop\ImageToText.py", line 6, in <module> txt = image_to_string(im)
File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 125, in image_to_string
raise TesseractError(status, errors)
pytesseract.pytesseract.TesseractError: (2, 'Usage: python pytesseract.py [-l lang] input_file')
原文由 Philippe 发布,翻译遵循 CC BY-SA 4.0 许可协议
来自 项目的自述文件:
因此,您必须确保 tesseract.exe 在您的计算机上(例如通过安装 Tesseract-OCR),然后将包含的文件夹添加到您的 PATH 环境变量,或使用
pytesseract.pytesseract.tesseract_cmd
属性声明它的位置