python - 打包应用程序时如何排除不必要的Qt *.so 文件?

标签 python pyinstaller packaging pyside2

使用 PyInstaller 成功打包我的 PySide 应用程序后,我在包文件夹中发现了许多不同的 *.so 文件。我很惊讶地看到我在项目中没有使用的库,例如:libQt53DAnimation.solibQt53DCore.solibQt5Multimedia.so等.

我没有在源代码中导入它们,也没有将它们包含在隐藏导入中。

正如我所读到的,PyInstaller 会自动查找应用程序运行所需的所有依赖项。如果我在打包后手动删除它们,那么我的应用程序运行时不会有任何更改/问题。这表明它们没有必要,也不应该将它们视为依赖项,不是吗?

那么有什么办法在打包时排除它们

最佳答案

如果您确定它们对于您的应用程序不是必需的,您可以通过规范文件中的分析排除它们。您只需按此处所示添加它们 https://pythonhosted.org/PyInstaller/spec-files.html#spec-file-operation .

您可以执行以下操作:

a.binaries = a.binaries - TOC([
  ('libQt53DAnimation.so', None, None),
  ('libQt53DCore.so', None, None),
  ('libQt5Multimedia.so', None, None),
])

还有一个 --exclude-module EXCLUDES 用于排除模块,但不确定它与您的情况有多相关。

不幸的是,pyinstaller 包含某些可选依赖项,正如 Hartmut Goebel 所解释的 here

PyInstaller does it's best to include only the needed modules - that's what PyInstaller is about :-). But many packages have optional dependencies which for your program might not be necessary, but are for other programs. PyInstaller can't know this and if PyInstaller would remove to much, other programs might fail. Please use option --exclude for this.

Please keep in mind, that alone Python's feature "full unicode support" add a lot of codecs modules, which look unecessary but are required for Python to work properly.

关于python - 打包应用程序时如何排除不必要的Qt *.so 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57466637/

相关文章:

Python PIL 图像保存

python - 每次值列表中的符号变化时计算差异

python - 无法导入 MongoClient

ios - 为什么我的 iOS 应用压缩得这么好?

go - 是否可以打包 Fyne 应用程序并一步交叉编译所述应用程序?

python - 无法安装matplotlib : fatal error C1083: Cannot open include file: 'ft2build.h' : No such file or directory

python - 如何更改 python 版本以与 pyinstaller 一起使用

python-2.7 - Pyinstaller 生成的 exe 无法在另一台计算机上运行

python - 使用 pyinstaller 时 .exe 文件过大

python - 打包一个django项目及其依赖为standalone "product"