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

本文涉及的产品
文档理解,结构化解析 100页
票证核验,票证核验 50次/账号
企业资质识别,企业资质识别 200次/月
简介: 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! Cou

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-OCRC:\ProgramFiles\Tesseract-OCR\tessdata

安装 pytesseract 模块

pipinstallpytesseract-ihttp://pypi.douban.com/simple--trusted-hostpypi.douban.com


安装Tesseract OCR

下载地址:https://github.com/UB-Mannheim/tesseract/wiki点击“tesseract-ocr-w64-setup-v4.0.0-beta.1.20180414.exe”下载安装。注意:安装的时候选中中文包(安装时把所有选项都勾上)。本人安装目录:C:\ProgramFiles\Tesseract-OCR\tessdata使用命令,查看版本号和支持语言:cdC:\ProgramFiles\Tesseract-OCRtesseract-vtesseract--list-langs-vtesseract--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.csdn.net/weixin_41194171/article/details/110433724

https://www.cnblogs.com/sea-stream/p/11542359.html

https://blog.csdn.net/magicianofcodes/article/details/79401622

目录
相关文章
|
编解码 C++ Python
成功解决LINK : fatal error LNK1181: 无法打开输入文件“avdevice.lib” error: command 'D:\\Program Files (x86)\\Micr
成功解决LINK : fatal error LNK1181: 无法打开输入文件“avdevice.lib” error: command 'D:\\Program Files (x86)\\Micr
成功解决LINK : fatal error LNK1181: 无法打开输入文件“avdevice.lib” error: command 'D:\\Program Files (x86)\\Micr
|
2月前
|
IDE 开发工具 Python
8-15| _ctypes.COMError: (-2147352567, '发生意外。', ('无法获取 Document 对象', 'AutoCAD', 'D:\\Program Files\\A
8-15| _ctypes.COMError: (-2147352567, '发生意外。', ('无法获取 Document 对象', 'AutoCAD', 'D:\\Program Files\\A
|
4月前
|
UED Python
【Python】已解决:FileNotFoundError: [Errno 2] No such file or directory: ‘D:\1. PDF’
【Python】已解决:FileNotFoundError: [Errno 2] No such file or directory: ‘D:\1. PDF’
143 0
|
6月前
|
Shell
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
102 0
|
Python
ERROR: file or directory not found: xx.py
​ 1、问题出现原因 在vscode中已导入pytest框架,做自动化demo小测试,运行Python文件一直出现如题错误,截图如下: ERROR: file or directory not found: xx.py  2、解决办法 1)直接把该文件移到当前主目录下,放在PYTHON-STUDY下 2)VSCode中右键tuopan.py文件,选择[在集成终端中打开],或者通过CD命令进入到tuopan.py文件所在目录 然后输入以下命令即可: 注:上述命令不是换行,在d:/前有空格 ,第一行信息为python所在安装路径,空格后的换行为运行的python文件的所在路径  
155 0
files 2
files 2
70 0
3.4 Files
3.4 Files
63 0
Argument 2 passed to think\\filesystem\\Driver::putFile() must be an instance of think\\File
Argument 2 passed to think\\filesystem\\Driver::putFile() must be an instance of think\\File
1197 0
cl.exe is unable to create an executable file
cl.exe is unable to create an executable file
132 0
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\