有关paddleocr在pyinstall中打包问题的解决方案

借鉴网址python解决paddleocr打包问题_pyinstaller怎么解决paddleocr中的动态导入-CSDN博客

在打包时我使用的spec文件如下:(需要将pathe和binaries换为自己的paddleocr路径)

block_cipher = None
a = Analysis(['main.py'],
     pathex=['E:\\PyEnviroment\\Lib\\site-packages\\paddleocr', 'E:\\PyEnviroment\\Lib\\site-packages\\paddle\\libs'],
     binaries=[('E:\\PyEnviroment\\Lib\\site-packages\\paddle\\libs', '.')],
     datas=[],
     hiddenimports=['framework_pb2','scipy.special.cython_special','skimage','skimage.feature._orb_descriptor_positions','skimage.filters.edges', 'skimage.data._fetchers'],
     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')

找到对应路径,在终端中运行命令(可在conda虚拟环境中运行)

pyinstaller main.spec

以下是我的使用示例-y参数表示在进行打包过程中对所有的确认提示都选择yes,也就是自动确认。这样可以在打包过程中避免出现需要手动确认的提示,使得整个打包过程更加自动化。

打包完成应该出现这样的目录结构(build为临时文件,可删)

运行main.exe可能出现以下问题(似乎是paddleocr在动态导入库时导入失败了)

ModuleNotFoundError: No module named ‘ppocr’

ModuleNotFoundError: No module named ‘tools.infer’

将paddleocr中的文件夹放入_interal中

posted @ 2024-07-01 12:38  22201335  阅读(36)  评论(0编辑  收藏  举报