I have a PySide6 + QML application to pack to exe file with PyInstaller.
Here's my code:
main.qml
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
ApplicationWindow {
id: window
title: "Motor"
width: 500
height: 600
visible: true
maximumHeight: height
maximumWidth: width
minimumHeight: height
minimumWidth: width
}
main.py
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
import sys
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine(parent=app)
engine.load("main.qml")
sys.exit(app.exec_())
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
motor.spec
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['E:\\Projects\\motor\\GUI'],
binaries=[],
datas=[('main.qml', '.'), ('settings.ini', '.')],
hiddenimports=['PySide6.QtCore', 'PySide6.QtGui', 'PySide6.QtQml'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='MotorGUI',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='MotorGUI')
After pack with pyinstaller motor.spec
, I copied plugins
, qml
and translations
folder from python/site-pack/PySide6 folder to the exe's PySide6 folder.
When I run the exe file, I got:
QQmlApplicationEngin failed to load component
file:///E:/Projects/motor/GUI/dist/MotorGUI/main.qml:1:1: Cannot load library E:\Projects\motor\GUI\dist\MotorGUI\PySide6\qml\QtQuick\qtquick2plugin.dll
The qtquick2plugin.dll
actually exists.
my python version is 3.8.6
PySide==6.0.0
pyinstaller==4.2
I've found the root cause. It lacks of dll of QT.
I fix this by copying all .dll file in the pyside Qt folder to the exe's folder.
Then it runs perfectly.
After that, I mamually remove redundant dll one by one to determine the minimal requirements.
Finally add the dll in spec file