文件 tesseract.exe 不存在

新手上路,请多包涵

我已经使用安装了 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 许可协议

阅读 1k
2 个回答

来自 项目的自述文件

 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'))

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

原文由 Antwane 发布,翻译遵循 CC BY-SA 3.0 许可协议

对于和我情况相同的人: 是一个 tesseract-OCR 下载器。下载完成后,转到您选择的路径,应该有一个名为 tesseract.exe 的文件,复制该文件的路径并将其粘贴到 pytesseract.exe

原文由 Philippe 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题