python解决paddleocr打包问题

虽然网上都有资料查询,但是都是单一问题,为了大家节省时间特意收集整理,多多点赞

1、首先确保是最新的库,因为最新的库修复了“”No module named 'tools'“问题,旧的代码库采用的是动态加载

__dir__ = os.path.dirname(__file__)

import paddle

sys.path.append(os.path.join(__dir__, ''))
def _import_file(module_name, file_path, make_importable=False):
    spec = importlib.util.spec_from_file_location(module_name, file_path)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    if make_importable:
        sys.modules[module_name] = module
    return module

tools = _import_file(
    'tools', os.path.join(__dir__, 'tools\__init__.py'), make_importable=True)
ppocr = importlib.import_module('ppocr', 'paddleocr')
ppstructure = importlib.import_module('ppstructure', 'paddleocr')

2、使用pyinstaller -collect-all paddleocr --onefile main.py

3、找到spec文件在hiddenimports 添加

hiddenimports=['framework_pb2','scipy.special.cython_special','skimage','skimage.feature._orb_descriptor_positions','skimage.filters.edges', 'skimage.data._fetchers']

4、进入paddleocr修改

from ppstructure.predict_system import StructureSystem, save_structure_res, to_excel

from ppstructure.predict_system import StructureSystem, save_structure_res, to_excel,TextSystem

class PaddleOCR(predict_system.TextSystem)

class PaddleOCR(TextSystem)

5、pyinstaller main.spec

上面打包成功后会出现缺少mklml.dll文件,此文件在\paddle\libs 里面所以可以单独加载它也可以

可以用以下spec:

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')

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值