Python pytesseract 找不到指定的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34225927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:38:46  来源:igfitidea点击:

pytesseract cannot find the file specified

pythontesseractpython-tesseract

提问by jason m

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)

and the error response I get back is:

我得到的错误响应是:

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

Any guidance would be fantastic.

任何指导都会很棒。

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

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

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

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

采纳答案by MaxU

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

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

First, make sure you have installed/copied Tesseract-OCR executables.

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

Windows can't find the executable tesseractin the directories specified in your PATHenvironment variable. So either make sure that the directory containing tesseractis in your PATHvariable or overwrite tesseract_cmdvariable in your Python script like as following (put your PATH instead):

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

import pytesseract

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

Beside that make sure that TESSDATA_PREFIXWindowsenvironment variable is set to the directory, containing tessdatadirectory. For example:

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

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

if tessdatalocation is: C:\Program Files (x86)\Tesseract-OCR\tessdata

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