Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux/PyInstaller: Exclude unneeded libraries #366

Merged
merged 1 commit into from
Nov 19, 2023

Conversation

guihkx
Copy link
Contributor

@guihkx guihkx commented Nov 16, 2023

Excluding these Linux libraries doesn't seem to cause any side-effects at runtime (they're also not present in the AppImage).

And the benefit of this, is a reduction of 15 MiB in the final size of the Linux binary, which should also slightly reduce the app's startup time (but don't quote me on that). :)

@guihkx guihkx changed the title Llinux/PyInstaller: Exclude unneeded libraries Linux/PyInstaller: Exclude unneeded libraries Nov 16, 2023
Copy link
Owner

@DevilXD DevilXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can merge this easily, but I wanted to point out that PyInstaller has other ways of doing this, it seems. Specifically, the Analysis class has an excludes option, that looks simpler to use: https://stackoverflow.com/a/42249386/8576445

There's also this: https://pyinstaller.org/en/stable/advanced-topics.html?highlight=Analysis#the-tree-class

Please consider using them instead of "subtracting" a TOC instance.

build.spec Outdated Show resolved Hide resolved
@guihkx
Copy link
Contributor Author

guihkx commented Nov 18, 2023

Specifically, the Analysis class has an excludes option

I tried this:

diff --git a/build.spec b/build.spec
index f61095d..103485a 100644
--- a/build.spec
+++ b/build.spec
@@ -65,7 +65,7 @@ a = Analysis(
     ["main.py"],
     pathex=[],
     datas=datas,
-    excludes=[],
+    excludes=["libicudata.so.66", "libicuuc.so.66", "librsvg-2.so.2"],
     hookspath=[],
     noarchive=False,
     runtime_hooks=[],

But it didn't work. If I understand the documentation correctly, excludes is specific to Python packages/modules, not files.

There's also this: https://pyinstaller.org/en/stable/advanced-topics.html?highlight=Analysis#the-tree-class

This one I couldn't quite understand how to use in our case, sorry... :(

Please consider using them instead of "subtracting" a TOC instance.

How about this approach:

diff --git a/build.spec b/build.spec
index e9d235f..080c00d 100644
--- a/build.spec
+++ b/build.spec
@@ -76,6 +76,13 @@ a = Analysis(
     win_private_assemblies=False,
     win_no_prefer_redirects=False,
 )
+# Exclude unneeded Linux libraries
+excluded_binaries = [
+	"libicudata.so.66",
+	"libicuuc.so.66",
+	"librsvg-2.so.2"
+]
+a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])
 pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
 exe = EXE(
     pyz,

Which I got from here.

Copy link
Owner

@DevilXD DevilXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the source code of whatever PyInstaller version I have installed right now, the TOC class is deprecated:
picture

How about...

build.spec Outdated Show resolved Hide resolved
Excluding these Linux libraries doesn't seem to cause any side-effects
at runtime (they're also not present in the AppImage).

And the benefit of this, is a reduction of 15 MiB in the final size of
the Linux binary, which should also slightly reduce the app's startup
time (but don't quote me on that). :)
@guihkx guihkx force-pushed the linux-pyinstaller-diet branch from 605541c to abf857a Compare November 19, 2023 12:44
@DevilXD
Copy link
Owner

DevilXD commented Nov 19, 2023

Very well 🙂

@DevilXD DevilXD merged commit 81d4e7b into DevilXD:master Nov 19, 2023
4 checks passed
@guihkx guihkx deleted the linux-pyinstaller-diet branch November 19, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants