我已经安装了pytesseract
图书馆使用
pip install pytesseract
当我尝试使用image_to_text
方法,它给了我一个
FileNotFoundError: [WinError 2] 系统找不到指定的文件
我用谷歌搜索了一下,发现我应该更改 pytesseract.py 文件和行中的某些内容
tesseract_cmd = 'tesseract'
应该成为
tesseract_cmd = path_to_folder_that_contains_tesseractEXE + 'tesseract'
我搜索过但没有找到tesseract.exe
我的 Python 文件夹中的文件,然后我重新安装了库,但该文件仍然不存在。最后,我将该行替换为:
tesseract_cmd = path_to_folder_that_contains_pytesseractEXE + 'pytesseract'
我的程序抛出:
pytesseract.pytesseract.TesseractError: (2, '用法: python pytesseract.py [-l lang] input_file')
我该怎么做才能让我的程序正常运行?
P.S 这是我的程序代码:
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')