Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to optimize dlls when compiling using Nuitka for PySide6?
Qt 6.11 is out! See what's new in the release blog

How to optimize dlls when compiling using Nuitka for PySide6?

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 697 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    juanxd4516
    wrote on last edited by
    #1

    Hi, I am having problems optimizing my app size, currently i am compiling using nuitka with this script:

    import os
    import subprocess
    import sys
    from pathlib import Path
    import argparse
    
    ENTRY_POINT = "RoboForger/main.py"
    OUTPUT_NAME = "RoboForger"
    
    def build(debug=False):
        project_root = Path(__file__).parent
        resources_dir = project_root / "RoboForger" / "resources"
        bin_dir = resources_dir / "bin" / "libredwg"
    
        cmd = [
            sys.executable, "-m", "nuitka",
            "--standalone",
            f"--output-filename={OUTPUT_NAME}",
            "--output-dir=dist",
    
            "--enable-plugin=pyside6",
            # TO REMEMBER: qt plugins are the folders from PySide6 library where the dlls
            # are stored. For example, the "platforms" folder contains the "qwindows.dll" file
            # renderers for 3D rendering (opengl)
            # platforms for Windows platform support
            # "--include-qt-plugins=renderers,platforms,qml",
    
            f"--windows-icon-from-ico={resources_dir / 'icon.ico'}",
    
            f"--include-data-dir={resources_dir}=resources",
            f"--include-data-files={bin_dir / 'dwg2dxf.exe'}=resources/bin/libredwg/dwg2dxf.exe",
    
            "--nofollow-import-to=typing",
            "--nofollow-import-to=types",
            
            # exclude unittest library if found
            # "--nofollow-import-to=unittest",
    
            "--msvc=latest",
    
            "--company-name=JuSo",
            "--product-name=RoboForger",
            "--file-version=2.1.0",
    
            "--windows-console-mode=disable",
    
            "--jobs=8",
            "--lto=no" if debug else "--lto=yes",
    
            ENTRY_POINT
        ]
    
        if debug:
            cmd += [
                "--debug",
                "--unstripped",
                "--no-debug-immortal-assumptions",
                "--python-flag=-v",
                "--windows-console-mode=force",
            ]
    
        print("\n--- Starting Nuitka Build ---")
        print(" ".join(cmd))
    
        subprocess.run(cmd, check=True)
    
        print("\nBuild successful!")
        print(f"Output: dist/{OUTPUT_NAME}.dist")
    
    if __name__ == "__main__":
        if not Path("pyproject.toml").exists():
            print("Run this script from the project root")
            sys.exit(1)
    
        parser = argparse.ArgumentParser(description="Build RoboForger with Nuitka")
        parser.add_argument("--debug", action="store_true", help="Build in debug mode")
        args = parser.parse_args()
    
        build(debug=True if args.debug else False)
    

    I want to remove those unnecesary dlls, for example:

    • qt6webenginecore.dll
    • qt6webchannel.dll
    • qt6webchannelquick.dll
    • qt6webenginequick.dll
    • qt6webenginequickdelegatesqml.dll
    • qt6websockets.dll
    • qt6webview.dll
    • qt6webviewquick.dll
    • ...
      Does any of you have a solution other than manually removing those files once the compilation is made?

    The project I am building is this one: https://github.com/JuanSobalvarro/RoboForger/tree/main

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shyamnath
      wrote on last edited by
      #4

      Hey @juanxd4516

      You can use the following Nuitka opiton

      --noinclude-dlls=PATTERN
                          Do not include DLL files matching the filename pattern
                          given. This is against the target filename, not source
                          paths. So ignore a DLL 'someDLL' contained in the
                          package 'package_name' it should be matched as
                          'package_name/someDLL.*'. Default empty.
      

      to exclude specific .dll's. If you are using pyside6-deploy, you can modify the extra_args option of the initially generated pysidedeploy.spec with the --noinclude-dlls option

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi and welcome to devnet,

        I think this is an issue you should bring to the nuitka authors.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • J Offline
          J Offline
          juanxd4516
          wrote on last edited by
          #3

          Oh, my bad! Thanks!!

          1 Reply Last reply
          0
          • J juanxd4516 has marked this topic as solved on
          • S Offline
            S Offline
            Shyamnath
            wrote on last edited by
            #4

            Hey @juanxd4516

            You can use the following Nuitka opiton

            --noinclude-dlls=PATTERN
                                Do not include DLL files matching the filename pattern
                                given. This is against the target filename, not source
                                paths. So ignore a DLL 'someDLL' contained in the
                                package 'package_name' it should be matched as
                                'package_name/someDLL.*'. Default empty.
            

            to exclude specific .dll's. If you are using pyside6-deploy, you can modify the extra_args option of the initially generated pysidedeploy.spec with the --noinclude-dlls option

            1 Reply Last reply
            2
            • J juanxd4516 has marked this topic as solved on
            • J Offline
              J Offline
              juanxd4516
              wrote on last edited by
              #5

              Thanks! That solves everything, I only need to control which add on i use to not break things, and it seems to run fine!!

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                You might also want to check for the plugins you don't use.

                That said, it might be worth checking with the nuitka folks about supporting the exclusion of Qt modules rather than having to list all the dlls.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved