文件 tesseract.exe 不存在

Phi*_*ppe 6 python python-3.x

我已经pytesseract使用安装了该库

\n\n
pip install pytesseract\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我尝试使用该image_to_text方法时,它给了我一个

\n\n
\n

FileNotFoundError: [WinError 2] 系统找不到指定的文件

\n
\n\n

我用谷歌搜索了一下,发现我应该更改 pytesseract.py 文件和行中的某些内容

\n\n
tesseract_cmd = \'tesseract\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

应该成为

\n\n
tesseract_cmd = path_to_folder_that_contains_tesseractEXE + \'tesseract\'  \n
Run Code Online (Sandbox Code Playgroud)\n\n

我搜索并没有tesseract.exe在我的 Python 文件夹中找到任何文件,然后我重新安装了该库,但该文件仍然不存在。最后,我将该行替换为:

\n\n
tesseract_cmd = path_to_folder_that_contains_pytesseractEXE + \'pytesseract\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的程序抛出:

\n\n
\n

pytesseract.pytesseract.TesseractError: (2, \'用法: python pytesseract.py [-l lang] input_file\')

\n
\n\n

我该怎么做才能让我的程序正常运行?

\n\n

PS这是我的程序代码:

\n\n
from pytesseract import image_to_string\nfrom PIL import Image, ImageEnhance, ImageFilter\n\nim = Image.open(r\'C:\\Users\\\xd0\xa4\xd0\xb8\xd0\xbb\xd0\xb8\xd0\xbf\xd0\xbf\\Desktop\\ImageToText_Python\\NoName.png\') \nprint(im)\n\ntxt = image_to_string(im)\nprint(txt)\n
Run Code Online (Sandbox Code Playgroud)\n\n

第一次尝试的完整回溯:

\n\n
File "C:/Users/user/Desktop/ImageToText.py", line 10, in <module>\ntext = pytesseract.image_to_string(im)\nFile "C:\\Python\\lib\\site-packages\\pytesseract\\pytesseract.py", line 122, in \nimage_to_string config=config)\nFile "C:\\Python\\lib\\site-packages\\pytesseract\\pytesseract.py", line 46, in \nrun_tesseract proc = subprocess.Popen(command, stderr=subprocess.PIPE)\nFile "C:\\Python\\lib\\subprocess.py", line 947, in __init__ restore_signals, start_new_session)\nFile "C:\\Python\\lib\\subprocess.py", line 1224, in _execute_child startupinfo)\nFileNotFoundError: [WinError 2]The system can not find the file specified\n
Run Code Online (Sandbox Code Playgroud)\n\n

第二次尝试的完整回溯

\n\n
Traceback (most recent call last):\nFile "C:\\Users\\user\\Desktop\\ImageToText.py", line 6, in <module> txt = image_to_string(im)\nFile "C:\\Python\\lib\\site-packages\\pytesseract\\pytesseract.py", line 125, in image_to_string\nraise TesseractError(status, errors)\npytesseract.pytesseract.TesseractError: (2, \'Usage: python pytesseract.py [-l lang] input_file\')\n
Run Code Online (Sandbox Code Playgroud)\n

Ant*_*ane 6

来自项目的自述文件

try:
    import Image
except ImportError:
    from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = '<full_path_to_your_tesseract_executable>'
# Include the above line, if you don't have tesseract executable in your PATH
# Example tesseract_cmd: 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))
Run Code Online (Sandbox Code Playgroud)

因此,您必须确保 tesseract.exe 在您的计算机上(例如通过安装 Tesseract-OCR),然后将包含的文件夹添加到您的 PATH 环境变量中,或者使用pytesseract.pytesseract.tesseract_cmd属性声明它的位置