Python PyteSeract错误窗口错误[错误2]
您好,我正在尝试使用python库pytesseract从图像中提取文本。 请查找代码:Python PyteSeract错误窗口错误[错误2],python,ocr,python-tesseract,windowserror,Python,Ocr,Python Tesseract,Windowserror,您好,我正在尝试使用python库pytesseract从图像中提取文本。 请查找代码: from PIL import Image from pytesseract import image_to_string print image_to_string(Image.open(r'D:\new_folder\img.png')) 但出现了以下错误: Traceback (most recent call last): File "<stdin>", line 1, in <
from PIL import Image
from pytesseract import image_to_string
print image_to_string(Image.open(r'D:\new_folder\img.png'))
但出现了以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Python27\lib\site packages\pytesseract\pytesseract.py”,第161行,在图像\u到\u字符串中
config=config)
文件“C:\Python27\lib\site packages\pytesseract\pytesseract.py”,第94行,在run\u tesseract中
stderr=子流程(管道)
文件“C:\Python27\lib\subprocess.py”,第710行,在_init中__
错误读取,错误写入)
文件“C:\Python27\lib\subprocess.py”,第958行,在执行子进程中
startupinfo)
WindowsError:[错误2]系统找不到指定的文件
我没有找到具体的解决办法。谁能帮我做什么。还有什么要下载的或者我可以从哪里下载的等等
提前感谢:)我也遇到了同样的问题,读完这篇文章后很快找到了解决办法: 只需将其适应Windows,即可替换以下代码:
tesseract_cmd = 'tesseract'
与:
(需要double
\\
才能首先在字符串中转义\
)您的计算机中需要安装Tesseract OCR引擎(“Tesseract.exe”)。如果未在计算机中配置路径,请在pytesseract.py(tesseract.py)中提供完整路径
安装Google Tesseract OCR(如何在Linux、Mac OSX和Windows上安装引擎的其他信息)。您必须能够作为tesseract调用tesseract命令。如果情况并非如此,例如,因为tesseract不在您的路径中,您必须更改tesseract.py顶部的“tesseract_cmd”变量。在Debian/Ubuntu下,您可以使用软件包tesseract ocr。适用于Mac OS用户。请安装自制软件包tesseract
由于子流程无法找到二进制文件(tesser可执行文件),因此出现异常 安装过程分为三步: 1.下载/安装系统级libs/二进制文件:
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
对于各种不同的操作系统,这里是。对于MacOS,您可以使用brew直接安装它
安装Google Tesseract OCR(如何安装
Linux、Mac OSX和Windows上的引擎)。您必须能够调用
tesseract命令作为tesseract。例如,如果不是这样的话
因为tesseract不在您的路径中,所以您必须更改
tesseract.py顶部的“tesseract_cmd”变量。在下面
Debian/Ubuntu您可以使用tesseract ocr软件包。适用于Mac OS用户。
请安装自制软件包tesseract
对于:
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
旧版本3.02的安装程序可从Windows获得
我们的下载页面。这包括英语培训数据。如果你
要使用另一种语言,请下载相应的培训数据,
使用7-zip解包,并将.traineddata文件复制到
“tessdata”目录,可能是C:\Program Files\Tesseract OCR\tessdata
要从任何位置访问tesseract OCR,您可能必须添加
路径的tesseract OCR二进制文件所在的目录
变量,可能是C:\Program Files\teseract OCR
可以从下载.exe
2.安装Python软件包
pip install pytesseract
3.最后,您需要在路径中包含tesseract二进制文件 或者,您可以在运行时设置它:
import pytesseract
pytesseract.pytesseract.tesseract_cmd = '<path-to-tesseract-bin>'
- 上面的行将使其临时工作,对于永久解决方案,将
添加到tesseract.exe
-例如路径
”PATH=%PATH%;“C:\Program Files(x86)\teseract OCR
- 除此之外,请确保将
Windows环境变量设置为包含TESSDATA目录的目录。例如:TESSDATA\u PREFIX
TESSDATA\u PREFIX=C:\Program Files(x86)\Tesseract OCRfrom PIL import Image import pytesseract pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract' print pytesseract.image_to_string(Image.open(r'D:\new_folder\img.png'))
C:\ProgramFiles(x86)\Tesseract OCR\tessdata
你的例子是:
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
print pytesseract.image_to_string(Image.open(r'D:\new_folder\img.png'))
我也面临着同样的问题,关于pytesseract。 我建议您在linux环境中工作,以解决此类错误。 在linux中执行以下命令:
pip install pytesseract
sudo apt-get update
sudo apt-get install pytesseract-ocr
希望这能奏效