解决pytesseract.pytesseract.TesseractError: (1, ‘Error opening data file C:\\Program Files\\Tesseract-

pytesseract.pytesseract.TesseractError: (1, ‘Error opening data file C:\Program Files\Tesseract-OCR\tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your “tessdata” directory. Failed loading language ‘chi_sim’ Tesseract couldn’t load any languages! Could not initialize tesseract.’)

报错信息
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Program Files\\Tesseract-OCR\\tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'chi_sim\' Tesseract couldn\'t load any languages! Could not initialize tesseract.') 
解决办法
path = "img\\text-img.png"

testdata_dir_config = '--tessdata-dir "C:\\ProgramFiles\\Tesseract-OCR\\tessdata"'

textCode = pytesseract.image_to_string(Image.open(path), config=testdata_dir_config, lang='chi_sim') 
若不能使用,配置环境变量
Tesseract-OCR
C:\Program Files\Tesseract-OCR\tessdata 
安装 pytesseract 模块
pip install pytesseract -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
安装Tesseract OCR
下载地址:https://github.com/UB-Mannheim/tesseract/wiki 
点击“tesseract-ocr-w64-setup-v4.0.0-beta.1.20180414.exe”

下载安装。注意:安装的时候选中中文包(安装时把所有选项都勾上)。本人安装目录:C:\Program Files\Tesseract-OCR\tessdata

使用命令,查看版本号和支持语言:
cd C:\Program Files\Tesseract-OCR  
tesseract -v tesseract --list-langs -v tesseract --list-langs  # 查看Tesseract-OCR支持语言 
配置tesseract运行文件
...\Lib\site-packages\pytesseract\pytesseract.py 

找到文件:tesseract_cmd = 'tesseract'
修改为:tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'       你放tesseract.exe的路径

Github地址:https://github.com/UB-Mannheim/tesseract/wiki

识别中文时,如果还是报错,可以将中文包下载到本地。

推荐阅读:
https://blog.youkuaiyun.com/weixin_41194171/article/details/110433724
https://www.cnblogs.com/sea-stream/p/11542359.html
https://blog.youkuaiyun.com/magicianofcodes/article/details/79401622

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值