Script for removing unnecessary libs from a PySide6+Linux build

10 views
Skip to first unread message

Tord Dellsén

unread,
May 16, 2022, 8:40:53 AM5/16/22
to PyInstaller
Hi all, i've created the script below which i hope can be useful for others

If you find this sort of thing useful i'd be happy to clean the code


import subprocess
import os
import os.path

REMOVED_DIR = "removed"

os.chdir("../dist/your-application")
print(f"{os.getcwd()=}")
if not os.path.isdir(REMOVED_DIR):
    os.mkdir(REMOVED_DIR)

# These files are used after the application has been started, so are not detected by our call to subprocess.run
PROTECTED_FILES = ["libQt6Multimedia.so.6", "libQt6Svg.so.6"]

all_files_in_base_dir = os.listdir(os.getcwd())
selected_so_files_in_base_dir = [fn for fn in all_files_in_base_dir if ".so" in fn and fn not in PROTECTED_FILES]

for filename in selected_so_files_in_base_dir:
    cur_path = os.path.join(os.getcwd(), filename)
    new_path = os.path.join(os.getcwd(), REMOVED_DIR, filename)
    os.rename(cur_path, new_path)
    try:
        shell_result = subprocess.run(
            "./your-application",
            stdout=subprocess.PIPE, timeout=2)
        # If we get here it means the application didn't start, so we need the file, and therefore move it back
        os.rename(new_path, cur_path)
        print(f"+++++ We need this file: '{filename}' --- so it has been moved back to the base dir")
    except subprocess.TimeoutExpired:
        print(f"----- We don't need this file: '{filename}' --- so it has been moved to the '{REMOVED_DIR}' dir")



Here is a link to the source for my own project, this file is more messy though: https://gitlab.com/mindfulness-at-the-computer/mindfulness-at-the-computer/-/blob/master/varia/so_files.py

Lisa Leatherby

unread,
May 16, 2022, 5:16:45 PM5/16/22
to pyins...@googlegroups.com
Thank you. This was really nice of you to send around. 

Sent from my iPhone

On May 16, 2022, at 7:46 AM, Tord Dellsén <tord.d...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/b5b76573-5f52-4fcc-bebd-6cabf21abc63n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages