Python(Pyside6) + QML packed to zipapp, how?
-
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.4The project is as simple as:
testapp/ |- __main__.py |- main.qmlI 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 -
@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.qmland 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 -
S SGaist has marked this topic as solved on