The most size-efficient way to build Windows app from a PySide app
-
wrote on 18 Oct 2021, 08:59 last edited by midnightdim
I have an open source PySide app that I'd like to build and distribute as a Windows desktop app (and also Mac and Linux in the future).
I'm currently usingcxfreeze
with a build script to build the app and Inno Setup to create the installer.I noticed that when I build the app with cxfreeze the biggest folder inside
lib
folder isPySide2
. It's around 322Mb when I build it.
The app is rather minimalistic, so it's a bit confusing that even the packaged installer is almost 100Mb. I'd like to reduce this size as much as possible.I noticed that I can delete some big files inside
PySide2
subfolder and it doesn't affect the functioning of the app, because I'm not using the corresponding components:Qt5WebEngineCore.dll
,Qt5Designer.dll
, etc.I also found that it's safe to delete some subfolders like
examples
,resources
,qml
and eventranslations
.So my questions are:
- What's the best way to build an executable app from a PySide app for Windows (7,10)?
- How can I get rid of unused files and folders? How can this be automated?
- What's the best practice for building the app for Mac and Linux?
Thanks.
-
wrote on 18 Oct 2021, 11:21 last edited by
Hello @midnightdim 👋 I cannot say much about cxfreeze. According to the docs its one of the 2 that supports PySide6? nice.
Well. I dunno whats the best 🤷♀️ But I can tell about my process of building releases for Windows.I'm using PyInstaller and some post assembly python scripts for cleanup and installer creation. My stats are:
- ~58.5mb for the unpacked PySide2 python app dir
- ~27mb for the zipped portable pack
- ~18mb for the installer executable using 7zip self extractor.
I saw other people talking about using UPX to compress some of the Qt-dlls but so far I'm happy with the sizes. So I didn't fiddle with it.
-
Hello @midnightdim 👋 I cannot say much about cxfreeze. According to the docs its one of the 2 that supports PySide6? nice.
Well. I dunno whats the best 🤷♀️ But I can tell about my process of building releases for Windows.I'm using PyInstaller and some post assembly python scripts for cleanup and installer creation. My stats are:
- ~58.5mb for the unpacked PySide2 python app dir
- ~27mb for the zipped portable pack
- ~18mb for the installer executable using 7zip self extractor.
I saw other people talking about using UPX to compress some of the Qt-dlls but so far I'm happy with the sizes. So I didn't fiddle with it.
wrote on 19 Oct 2021, 04:15 last edited by midnightdim 11 Jan 2021, 16:42@ewerybody Hi and thanks!
Is it correct that you're shipping your app as a "portable version", i.e. without the installation?
I'm going to try reusing yourfinish_package.py
, looks like it does some cleanup that I'm looking for.
Could you please shed some light on what's the best way to apply these scripts? What kind of tweaking do I need to use it with my app?
Is there a simpler solution? For example, just a script that would delete unused dlls?Although I'm not using Qt6 yet, I'd really like to switch to PySide6/Qt6 in the future, so would be glad to hear the suggestions for building the app with
cxfreeze
. Or maybe pyinstaller is going to support it in the near future. -
@ewerybody Hi and thanks!
Is it correct that you're shipping your app as a "portable version", i.e. without the installation?
I'm going to try reusing yourfinish_package.py
, looks like it does some cleanup that I'm looking for.
Could you please shed some light on what's the best way to apply these scripts? What kind of tweaking do I need to use it with my app?
Is there a simpler solution? For example, just a script that would delete unused dlls?Although I'm not using Qt6 yet, I'd really like to switch to PySide6/Qt6 in the future, so would be glad to hear the suggestions for building the app with
cxfreeze
. Or maybe pyinstaller is going to support it in the near future.wrote on 19 Oct 2021, 10:14 last edited byHello @midnightdim,
First, did you try to use "exclude" argument in cxfreeze setup script ? It may help to reduce size according to this post on stackoverflow
Since you're planning to switch to PySide6, you may be interested by nuitka. It compiles Python code to c code and make a "true" executable. It's partially supported on PySide2 but seems PySide6 is fully supported. I didn't test it yet but it looks promising.
-
Hello @midnightdim,
First, did you try to use "exclude" argument in cxfreeze setup script ? It may help to reduce size according to this post on stackoverflow
Since you're planning to switch to PySide6, you may be interested by nuitka. It compiles Python code to c code and make a "true" executable. It's partially supported on PySide2 but seems PySide6 is fully supported. I didn't test it yet but it looks promising.
wrote on 19 Oct 2021, 15:20 last edited by@Gojir4 Thanks. Yes, I'm using "excludes", but the question is: what exactly should I exclude (at least in PySide). I know what I'm using, does it mean that I have to review all PySide2 packages and add everything that I don't use to "excludes"?
And yes, thanks for the tip, I looked at nuitka and it looks promising indeed. Going to try it, but @ewerybody 's approach seems very solid, so I'm reaching out to him to get some further advice.
1/5