1

I currently have a frozen binary created out of a PySide2 python program using PyInstaller, and it ends up having a very large file size. A script as small as a PySide2 window with Hello World can reach over 40MBs in size.

There are many unused bindings of PySide2 that are being included in the binary, and I've been wondering if there's any modern solution for stripping them from the frozen binary.

After a quick search, I only managed to find a tool called Hatchet from a library called PySideKick, but it's been unmaintained for years, and probably is not suitable for use with PySide2 or Python 3.

Guy Twig
  • 101
  • 2
  • 12

1 Answers1

1

There are a number of approaches you can take to reduce pyinstalled compiled filesizes:

  1. If you use anaconda, switching to virtualenv can lead to a significant reduction in the size of the compiled file. I made an virtualenv environment in pycharm specifically for compiling a project and it really helped. (more details: How to make pyinstaller not use anaconda and build a small-size exe file)

  2. You can exclude specific modules that you don't want compiled with the --exclude-module argument in pyinstaller.

  3. A better way to do the above is to edit the spec file as suggested in this answer: How to exclude unnecessary Qt *.so files when packaging an application?

Unfortunately, pyinstaller needs to package the python interpreter and some other dependencies so the filesize will always be larger than you (or me) would like. Double check in the dist file that the majority of your overhead is actually from PySide.

Joseph
  • 578
  • 3
  • 15
  • Thank you. Are there any tools I can use to know which Qt .so files are used and which aren't? – Guy Twig Sep 22 '20 at 13:40
  • not that I know of unfortunately, it is a shame hatchet is no longer supported at is looks like a really nice tool – Joseph Sep 22 '20 at 13:56