python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

一、先下载tesseract的安装程序并安装

下载地址为https://digi.bib.uni-mannheim.de/tesseract/

python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

 w64表示window64位版本,beta表示测试版本,下载对应电脑位数的版本安装程序exe并安装

我安装在D:\Tesseract-OCR下,并配置系统环境中点击确认。

python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

打开dos命令中输入tesseract --version 或者tesseract 不报错表示安装成功,注意我的tesseract版本为v4.0.0(下载whl时要对应相应的版本)

python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

二.pip安装tesseract对应python的tesserocr.whl的驱动库

whl下载地址为:https://github.com/simonflueckiger/tesserocr-windows_build/releases

python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

一定要下载对应的版本,cp35表示python3.5版本   amd64表示64位操作系统,本人操作系统为64位,python3.5版本。

下载过后通过pip安装whl文件,然后就可以在python中使用 import tesserocr模块了。

 

但是使用的时候依然会报tessdata路径错误

Failed to init API, possibly an invalid tessdata path: C(F):\\

一般你的文件在那个盘下,报错信息就会在那个盘下。

经过网上搜索,通过把D:\Tesseract-OCR\tessdata添加到环境变量中证明是不行的。

我的成功解决方式是在c(f)盘下创建个python3.5空文件(文件名为你安装python时的文件名,如果报错的盘下是你的安装python的地方时,就不用新建了,直接将tessdata复制到文件夹下即可),将D:\Tesseract-OCR盘下的tessdata数据复制到刚刚新建的c(f)://python3.5空文件夹中,然后顺利解决。

 

 

 

测试安装成功小程序:

 

图片为:python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

import tesserocr
from PIL import Image
image = Image.open('test.png')
result = tesserocr.image_to_text(image)
print(result)

结果为:

python中tesserocr安装教程及Failed to init API, possibly an invalid tessdata path: C:\\的解决方案

识别结果 还是不错的。