pytesseract找不到指定的文件

时间:2015-12-11 14:34:52

标签: python tesseract python-tesseract

我的代码很简单,如下:

change_door_status = WHEN PrimaryLock /= On THEN door :: {Open,Closed} END

我得到的错误回复是:

import pytesseract
from PIL import Image

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

任何指导都很棒。

将tesseract添加到我的路径变量帮助: 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

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

1 个答案:

答案 0 :(得分:49)

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

首先,请确保您拥有installed/copied Tesseract-OCR executables

Windows无法在tesseract环境变量中指定的目录中找到可执行文件PATH。因此要么确保包含tesseract的目录在您的PATH变量中,要么在Python脚本中覆盖tesseract_cmd变量,如下所示(改为使用PATH):

import pytesseract

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

除此之外,请确保将TESSDATA_PREFIX Windows 环境变量设置为包含tessdata目录的目录。例如:

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

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