打包应用程序时如何排除不必要的Qt *.so文件? [英] How to exclude unnecessary Qt *.so files when packaging an application?

查看:100
本文介绍了打包应用程序时如何排除不必要的Qt *.so文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After the successful packaging of my PySide app using PyInstaller, I've found lots of different *.so files in a package folder. I was surprised seeing libraries I don't use in my project, like: libQt53DAnimation.so, libQt53DCore.so, libQt5Multimedia.so and etc.

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

I didn't import them in source code and haven't include them in hidden imports.

正如我所读到的,PyInstaller 会自动查找应用程序运行所需的所有依赖项.如果我在打包后手动删除它们,那么我的应用程序将运行而没有任何更改/故障.那就是指出它们没有必要,也不应该将它们视为依赖项,不是吗?

As i have read, PyInstaller automatically finds all dependencies needed an app to run. If I delete them manually after the packaging, then my app running without any changes/troubles. That's points out that there is no need in them and they should not be treated as dependencies, aren't they?

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

So is there any way to exclude them while packaging

推荐答案

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

If you are sure that they are not necessary for your application you can exclude them with the Analysis in the spec file. You simply need to add them as shown here 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 用于排除模块,但不确定它与您的情况有多相关.

There is also an --exclude-module EXCLUDES for excluding modules but, not sure how relevant it is for your case.

不幸的是,pyinstaller 包含某些可选的依赖项,正如 Hartmut Goebel 在此处

Unfortunately, pyinstaller includes certain optional dependenices as Hartmut Goebel explains here

PyInstaller 最好只包含需要的模块 - 那就是PyInstaller 是关于什么的:-).但是很多包都有可选的您的程序可能不需要的依赖项,但对于其他程序.PyInstaller 无法知道这一点,如果 PyInstaller会删除太多,其他程序可能会失败.请使用选项-- 为此排除.

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.

请记住,仅 Python 的特性完整的 unicode支持"添加了很多编解码器模块,这些模块看起来没有必要,但实际上Python 正常工作所必需的.

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.

这篇关于打包应用程序时如何排除不必要的Qt *.so文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆