Error opening data file Tesseract-OCR\tessdata/eng.traineddata问题解决

时间:2021-12-19 08:54:38

Error opening data file Tesseract-OCR\tessdata/eng.traineddata问题解决

在安装完tesseract, pytesseract后执行测试命令,发现打印如下错误:

Error opening data file \Program Files (x86)\Tesseract-OCR\tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
Could not initialize tesseract.

一看上面的提示就是路径有问题,windows路径是\的
解决办法,添加TESSDATA_PREFIX的环境变量,设置为安装目录下的tessdata目录
如:D:\Program Files (x86)\Tesseract-OCR\tessdata

如果还是不行,设置了环境变量可能需要重启下才生效

最快捷的试验方法是,命令行设置环境变量后测试

SET TESSDATA_PREFIX=D:\Program Files (x86)\Tesseract-OCR\tessdata
tesseract 123.png 123.txt