Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Python(Pyside6) + QML packed to zipapp, how?
Forum Updated to NodeBB v4.3 + New Features

Python(Pyside6) + QML packed to zipapp, how?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 541 Views
  • 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.
  • N Offline
    N Offline
    noxnivi
    wrote on last edited by
    #1

    Good day,

    I'm (newbie on python and newbie on qml) working on a set of very simple programs for Desktop coded with Python and QML. They don't have specific dependencies other than pyside6. I've been struggling to pack the first one, searching ways to do it everywhere.

    This first one is just a .py file and a .qml file, in total 4.5 Kb. Using Nuitka to compile as '--standalone' it works though results in 65 Mb size, can't get it to work with '--onefile', but I discarded it because of the size.

    Zipapp seems to be the best option to get the program in a single file to move around as the result zipapp file is 8,5 kb. Nonetheless, I can't get it to work once zipped as it seems the qml file can't be loaded from within the zipapp file. I wouldn't need to pack dependencies as they would be available already in the systems where those apps will run(venv packages):

    python -m pip list
    Package            Version
    ------------------ -------
    pip                23.0.1
    PySide6            6.4.2
    PySide6-Addons     6.4.2
    PySide6-Essentials 6.4.2
    setuptools         65.5.0
    shiboken6          6.4.2
    wheel              0.38.4
    

    The project is as simple as:

    testapp/
        |- __main__.py
        |- main.qml
    

    I tried the methods using pkgutil module as well as importlib.resources without success.

    I would appreciate any insight on this matter.

    Thanks in advance.
    Regards,
    NN

    1 Reply Last reply
    0
    • N Offline
      N Offline
      noxnivi
      wrote on last edited by
      #2

      @noxnivi said in Python(Pyside6) + QML packed to zipapp, how?:

      t

      Well, finally I got it working after trying even the zipfile module. It works with the importlib.resources module but need to change the folder layout to this:

      testapp/
        |_  __init__.py
        |_  __main__.py
        |_ gui/
               |_ __init__.py
               |_ main.qml
      

      and in main.py add this code:

      qmlPack = importlib.resources.files("gui").joinpath("main.qml")
         qmlFile = importlib.resources.as_file(qmlPack)
      
         with qmlFile as qfile:
             engine.load(qfile)
      

      By doing this it works normally calling the main.py script (python main.py) as well as after zipapping (python -m zipapp testapp -p "/usr/bin/env python" -o testzapp) the "testapp" folder.

      This can be marked as solved then.

      Regards
      NN

      1 Reply Last reply
      1
      • SGaistS SGaist has marked this topic as solved on

      • Login

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