pyinstaller打包1

目的

在使用pyinstaller打包python程序时一直出问题,记录下以便后续查看。

打包过程

  1. 首先应该创建一个单独的python环境,以免打包后的exe包含了多余的包,导致exe文件过大。
  2. pyi-makespec.exe test.py 创建 test.spec 文件。spec文件官方说明:https://pyinstaller.org/en/stable/spec-files.html
  3. 修改test.spec文件。
  4. pyinstaller.exe test.spec 进行最后的打包。

出现的问题

  1. 运行打包后的exe,报错:找不到包;
  2. 添加自己写的包的搜索路径;
  3. 修改打包后的程序和文件夹名字;
block_cipher = None


a = Analysis(
    ['record_system_v28\\2record_system_v28.py'],
    pathex=['D:\PycharmProjects\HPI'],  # 当自己写的包找不到时,将包的搜索路径填入这里
    binaries=[],
    datas=[],
    hiddenimports=['qimage2ndarray','pyqtgraph','osgeo','configparser','socket_motor'],  # 当运行打包后的程序报找不到包的错误时,将包加入这里
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    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='2record_system_v28',  # 打包后的exe名
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='2record_system_v28',  # 打包后的文件夹名
)
  1. 自己写了一个影像读写包:基于gdal封装了一个类,但是打包后运行exe报错莫名其妙,最后通过把这个类放到主文件中解决。
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值