pytesseract 找不到指定的文件 [英] pytesseract cannot find the file specified

查看:125
本文介绍了pytesseract 找不到指定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码很简单,如下所示:

My code is straight forward and is the following:

import pytesseract
from PIL import Image

img = Image.open('C:/temp/foo.jpg')
img.load()
i = pytesseract.image_to_string(img)

我得到的错误响应是:

Traceback (most recent call last):
  File "img.py", line 6, in <module>
    i = pytesseract.image_to_string(img)
  File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 161, in image_to
_string
  File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 94, in run_tesse
ract
  File "C:\Users\%USER%\AppData\Local\Continuum\Anaconda\lib\subprocess.py",
line 710, in __init__
    errread, errwrite)
  File "C:\Users\%USER%\AppData\Local\Continuum\Anaconda\lib\subprocess.py",
line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

任何指导都会很棒.

将 tesseract 添加到我的路径变量有帮助:C:\Program Files (x86)\Tesseract-OCR

Adding tesseract to my path variable helped: C:\Program Files (x86)\Tesseract-OCR

但是现在尝试运行 pytesseract 时代码崩溃了.

But the code now crashes when trying to run the pytesseract piece.

推荐答案

刚遇到同样的错误并决定回答这个问题 - 它可能有助于某人节省时间...

Just hit the same error and decided to answer this question - it might help someone to save time...

首先,确保您安装/复制了 Tesseract-OCR 可执行文件.

Windows 在 PATH 环境变量中指定的目录中找不到可执行文件 tesseract.因此,请确保包含 tesseract 的目录在您的 PATH 变量中,或者像下面这样覆盖 Python 脚本中的 tesseract_cmd 变量(将您的 PATH代替):

Windows can't find the executable tesseract in the directories specified in your PATH environment variable. So either make sure that the directory containing tesseract is in your PATH variable or overwrite tesseract_cmd variable in your Python script like as following (put your PATH instead):

import pytesseract

pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'

此外确保TESSDATA_PREFIX Windows 环境变量设置为包含tessdata 目录的目录.例如:

Beside that make sure that TESSDATA_PREFIX Windows environment variable is set to the directory, containing tessdata directory. For example:

TESSDATA_PREFIX=C:\Program Files (x86)\Tesseract-OCR

如果 tessdata 位置是:C:\Program Files (x86)\Tesseract-OCR\tessdata

这篇关于pytesseract 找不到指定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆