PaddleOCR源码运行正常,打包exe后报 The pipeline (OCR) does not exist 问题解决方案

📅 2026/7/31 8:51:06
PaddleOCR源码运行正常,打包exe后报 The pipeline (OCR) does not exist 问题解决方案
一、问题背景软件开发阶段python main.py运行正常。但是使用打包工具生成exe后main.exe启动时报错。二、错误现象运行exemain.exe出现异常File paddlex\inference\pipelines\__init__.py, line 96, in load_pipeline_config Exception: The pipeline (OCR) does not exist! Please use a pipeline name or a config file path!完整调用链main.exe | | AlgorithmEngine | | OCR_detect.py | | PaddleOCR() | | paddleocr._pipelines.ocr | | paddlex.inference.pipelines | | load_pipeline_config() | | OCR pipeline不存在三、问题表现特点这个问题有一个明显特点源码运行正常开发环境python main.py可以正常ocrPaddleOCR(langch)OCR模型可以正常加载。打包后失败生成dist/ | └── main.exe运行main.exe报The pipeline (OCR) does not exist!说明Python环境中的PaddleOCR资源存在但是exe打包后的运行环境缺少相关文件。四、原因分析1. PaddleOCR 3.x架构变化PaddleOCR 3.x 不再只是python代码 模型文件而是引入PaddleOCR | | PaddleX Pipeline | | pipeline配置 | | OCR模型配置目录结构类似site-packages | | paddleocr | | paddlex | | inference | | pipelines | | OCR配置文件2. 打包工具无法自动识别动态资源PyInstaller / Nuitka 在分析frompaddleocrimportPaddleOCR时只能发现.py文件 .pyd文件 .dll文件但是不能自动发现.yaml .json .yml 模型配置 pipeline配置这些动态加载资源。运行时PaddleOCR()内部执行load_pipeline_config() | | 寻找 OCR pipeline | | 文件不存在 | | 报错五、为什么开发环境没有问题因为开发环境直接使用Python环境 | | site-packages | | paddlex | | pipeline配置存在而exe环境main.exe | | 打包目录 | | 缺少paddlex资源文件所以源码正常exe失败六、解决过程方法一确认资源是否被打包查看dist目录搜索paddlex正常应该存在paddlex | ├── inference | ├── pipelines | └── configs如果没有说明打包时遗漏。七、解决方案方案1增加hidden-import如果使用PyInstaller增加--hidden-importpaddleocr --hidden-importpaddlex例如pyinstaller main.py ^ --hidden-importpaddleocr ^ --hidden-importpaddlex但是只解决Python模块问题。方案2添加数据文件重点PaddleOCR依赖大量非Python文件。需要添加paddleocr资源目录 paddlex资源目录例如PyInstallerdatas[(xxx/site-packages/paddlex,paddlex),(xxx/site-packages/paddleocr,paddleocr)]加入.spec文件八、Nuitka解决方案如果使用Nuitka需要添加--include-packagepaddleocr --include-packagepaddlex同时加入数据文件--include-data-dir例如python-mnuitka main.py ^ --include-packagepaddleocr ^ --include-packagepaddlex ^ --include-data-dirC:\Users\admin\miniconda3\envs\pyside6\Lib\site-packages\paddlexpaddlex九、另一种推荐方案固定PaddleOCR版本如果项目用于工业部署建议不要直接使用PaddleOCR 3.x因为引入PaddleX依赖复杂打包困难工业项目推荐paddleocr 2.7.3 paddlepaddle 2.6.1调用方式ocrPaddleOCR(use_angle_clsTrue,langch)优点依赖简单打包稳定部署方便十、最终部署方案项目最终环境Python 3.10 YOLO: PyTorch GPU OCR: PaddleOCR 2.7.3 PaddlePaddle CPU PySide6: GUI OpenCV: 图像处理软件结构工业视觉软件 | AlgorithmEngine | ┌──────┴───────┐ YOLO OCR GPU CPU十一、总结错误The pipeline (OCR) does not exist!原因不是OCR模型错误PaddleOCR安装错误代码错误真正原因打包工具没有将PaddleOCR/PaddleX依赖的pipeline配置文件、资源文件一起打包。解决检查paddlex资源是否进入exe目录添加hidden-import添加data文件使用include-package/include-data-dir工业部署建议使用PaddleOCR 2.7.3降低复杂度开发环境正常python main.py打包失败main.exe本质区别开发环境 完整Python环境 exe环境 打包后的精简运行环境对于工业视觉软件打包不仅需要代码还需要所有动态加载资源。