pyinstaller 打包时第三方模块与图片资源加载

打包命令

pyinstaller --onefile --windowed **.py

 

修改**.spec 文件

pathex=['/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ddddocr'],

datas=[('./images', 'images'),('/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ddddocr/common.onnx','ddddocr')],

 

在 hooks 目录中添加文件

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks/hook-images.py

内容:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files
datas = collect_data_files('images')

 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks/hook-ddddocr.py

from PyInstaller.utils.hooks import collect_submodules, collect_data_files
datas = collect_data_files('ddddocr')

posted @ 2023-04-20 22:32  逸乐太子  阅读(142)  评论(0编辑  收藏  举报