TransWikia.com

Tool to reduce size of frozen Python app by programmatically removing (or excluding) unnecessary code

Software Recommendations Asked by CrazyChucky on September 25, 2021

I suspect this question may be applicable to other Python packages and other methods of freezing, but in my particular case I’m using PyInstaller to freeze an application built on PySide2. (I’ve also tried PyQt5, to see if there are any differences.)

Qt is a big framework, so by default the frozen app is huge, including many modules/plugins I’m not using, such as Qt3D and QtWebView. One approach to trim this down is to experimentally delete bundled libraries, testing to make sure the app still functions. Then PyInstaller can be told to leave these out in future builds, using methods such as the one suggested in this StackOverflow answer.

However, it seems there really should be a way of doing this programmatically, even if it’s not 100% foolproof. Looking around, I found what looks to be exactly that (and tailored for PySide in particular): PySideKick.Hatchet (description here). It analyzes an already-frozen app, follows imports to determine which classes and methods aren’t being accessed, then rebuilds the app with those parts left out.

There’s one big problem: it was last updated almost a decade ago, and only supports PySide 1. With the various static and dynamic Python analysis tools available today (Pyflakes, Vulture, Coverage), it seems like there ought to be a way to automate this sort of process, perhaps in a more standardized way than it looks like Hatchet did. I haven’t found anything yet that fits the bill. I could try making my own script, but I want to make sure I’m not reinventing the wheel.

It seems to me this could potentially take two forms:

  • Analyze the code to be frozen, and only freeze/package the parts needed
  • Analyze the app after freezing, and remove the unneeded parts (like Hatchet)

Do you know of any package that does this?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP