
Ocr之使用 pyinstall 打包 paddleocr
PaddleOCR
Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
项目地址:https://gitcode.com/gh_mirrors/pa/PaddleOCR

·
目录
零、运行环境介绍
一、安装pyinstaller
二、编辑spec文件
三、编辑入口python文件
七、打包后将模型文件、图片移动至文件夹内
六、打包后的文件内容截图
四、借鉴的文章(对其内容进行修正)
五、总结
零、运行环境介绍
- win10、64位系统、
- python 3.8.0
一、首先使用pip安装pyinstaller pip install pyinstaller
注意:
安装后使用pyinstaller
对paddleocr进行打包。打包后的文件能够运行的前提:本机可以通过 python 命令执行入口文件(入口文件后文有粘贴)
打包后的文件经测试可以在未安装python环境的系统进行使用. 很棒.^------------^!
PaddleOCR
Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
项目地址:https://gitcode.com/gh_mirrors/pa/PaddleOCR
二、使用的spec文件内容如下
-
注意:其中需要修改的部分是pathex中文件所在路径
文件内容摘抄自另一篇博文(❄点击可查看❄)# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['gui.py'], pathex=['E:/prgrames/Python/Python38/Lib/site-packages/paddleocr' , 'E:/prgrames/Python/Python38/Lib/site-packages/paddle/libs'], binaries=[('E:/prgrames/Python/Python38/Lib/site-packages/paddle/libs', '.')], datas=[], hiddenimports=[], hookspath=['.'], runtime_hooks=[], excludes=['matplotlib'], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='main', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=True) coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='main')
三. 入口python文件paddleocr.py
-
注意:img_path与 det_model_dir, rec_model_dir, cls_model_dir是生成的dist文件中模型和图片的相对路径, 用于exe文件查找模型和图片使用。(建议使用相对路径, 方便文件的迁移)
-
注意:在使用博文提供的此脚本后注释部分内容, 避免运行报错
注释内容:1. orc_result开头内容和 2. text='\n'开头内容
from paddleocr import PaddleOCR 模型路径下必须含有model和params文件 ocr = PaddleOCR(det_model_dir = './inference/ch_PP-OCRv3_det_infer/', # 检测模型所在文件夹 rec_model_dir = './inference/ch_PP-OCRv3_rec_infer/', # 识别模型所在文件夹。 cls_model_dir = './inference/ch_ppocr_mobile_v2.0_cls_infer/', # 分类模型所在文件夹。 #rec_char_dict_path = './dict/japan_dict.txt', # 识别模型字典路径。 #lang = 'en', use_angle_cls = True, # 是否加载分类模型 use_gpu = False) # 是否使用gpu img_path = './20240118154748.png' result = ocr.ocr(img_path, cls = True) #ocr_result=[line[1][0] for line in result] # 组合成列表形式 #text='\n'.join(ocr_result) # 回车符连接列表中的每个元素 print(result)
七、打包后将模型文件、图片移动至文件夹内
- paddleocr gitee地址
下载推理模型
并解压存储在对应目录下 - 如:识别模型目录下文件
六、打包后的文件内容截图
八、cmd执行main
注意:这里标红处为我希望得到的内容. 但仍需根据业务进行精简修改入口脚本等内容
四、借鉴的文章(对其内容进行修正)
-
PaddleOCR打包exe
测试后可以正常执行打包流程, 但安装完成后根据他的提示执行main.exe会报错
1. 将下图中 paddleocr安装目录下的tools文件夹 复制到 错误提示的路径下 2. python安装目录下 Python38\Lib\site-packages\paddleocr\tools
-
paddleocr打包exe错误汇总
解决了main.exe执行过程 extract_textpoint_slow module找不到的问题
1. 根据他的描述(他的提示移动 ppocr 至 dist下)发现不能解决问题。 2. 通过调整测试,将文件夹(ppocr)复制到 dist/main/_internal 下就可以了。 3. ppocr文件夹所在路径(python安装目录下) Python38\Lib\site-packages\paddleocr 4. 除此之外还有文件找不到的情况。尝试将对应文件夹粘贴到错误提示的路径
五、总结
- 打包前对入口python脚本进行调试。确保本地测试通过。
- 打包前paddleocr可运行使用
paddleocr gitee readme中有安装文档, 非常详细.
https://gitee.com/paddlepaddle/PaddleOCR/blob/release/2.7/doc/doc_ch/quickstart.md - 打包报错莫急,跟着报错提示渐行处理。并在必要时借鉴网络资料(我还查询过抖音的
豆包AI
,感觉还不错) - spec文件看似内容较多, 实则用的较少。有幸可以搜索到此篇文章
推荐内容
阅读全文
AI总结




Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
最近提交(Master分支:8 个月前 )
a80d2c89
2 天前
5d120f8f
4 天前
更多推荐
相关推荐
查看更多
PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
PaddleOCR

拉取来自百度的官方仓库
PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
热门开源项目
活动日历
查看更多
直播时间 2025-04-23 19:00:00

GitTalk:国内首个微服务编排框架Juggle实战解析
直播时间 2025-04-22 18:31:56

字节AI 黑科技!从 Manus Agent 入门 Eino
直播时间 2025-04-09 14:34:18

樱花限定季|G-Star校园行&华中师范大学专场
直播时间 2025-04-07 14:51:20

樱花限定季|G-Star校园行&华中农业大学专场
直播时间 2025-03-26 14:30:09

开源工业物联实战!
所有评论(0)