【pyinstaller】python打包工具

打包选项

选项含义
–runtime-tmpdir提取库和文件的位置,如果给定该选项,bootloader将忽略运行时操作系统定义的任何临时文件夹位置,将在此处创建_MEIxxxxxx文件夹。

打包一个文件

pyinstaller --onefile test.py

pyinstaller参数

参数含义
–onefile
–hidden-import导入隐藏的包,例:–hidden-import=gssapi.raw.cython_converters

问题收集

使用pyinstaller时遇见一个坑,打包环境上安装了gssapi,并且手动导入是成功的,看下图:
在这里插入图片描述
使用Pyinstaller打出来的包,运行时报错没有模块名叫 gssapi.raw.cython_converters:

ImportError: GSSAPIProxy requires the Python gssapi library: No module named 'gssapi.raw.cython_converters

在这里插入图片描述

方案一:

参照资料:https://github.com/pyinstaller/pyinstaller/issues/8014 把gssapi.raw所有的子模块给配置到hiddenimports中能运行成功。

from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('gssapi.raw')
...
hiddenimports += [...]  # any other hidden imports you want to addd
...
a = Analysis(
   ...
   hiddenimports=hiddenimports,
   ...
)

方案二:
后来又发现了一个方案,在代码中手动指定导入的包,比如报错缺少No module named gssapi.raw.cython_converters,在代码里就手动导入from gssapi.raw import cython_converters,尽管代码中并没有直接使用cython_converters,目的是为了让pyinstaller打包时能将这个包打进去。试了之后发现这个方法也是可以的。

pyinstaller并不太智能啊,花费了挺久时间。

暂时记录该方案,以后说不定还能用到。

参考资料

  • 官方文档:https://pyinstaller.org/en/stable/index.html
  • PyInstaller使用指南与选项大全:https://zhuanlan.zhihu.com/p/671665624
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值