Search code examples
pythonpyinstallerpackagingpyside2

How to exclude unnecessary Qt *.so files when packaging an application?


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.

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


Solution

  • 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.

    Here is what you could do:

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

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

    Unfortunately, pyinstaller includes certain optional dependenices as Hartmut Goebel explains 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.