打包选项
选项 | 含义 |
---|---|
–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