I\'m trying to build an app using pyinstaller, PyQt5 and qml (see files below) using the following command.
pyrcc5 pyqt5_qml.qrc > pyqt5_qml_qrc.py
pyinst
Working with PyInstaller I've noticed that it simply fails to bundle QML dependencies then freezing an app. You can check whether it is your case as well by copying QtQuick
and QtQuick.2
folders from python site packages (<your_python_path>\Lib\site-packages\PyQt5\Qt\qml
) and placing it near freezed executable:
QtQuick
QtQuick.2
your_executable.exe
If app works after this, you can edit .spec
file to bundle these folders automatically (pyinstaller generate .spec
-file on first run).
# -*- mode: python -*-
import os
import site
block_cipher = None
site_packages_dir = site.getsitepackages()[1]
qml_dir = os.path.join(site_packages_dir, 'PyQt5', 'Qt', 'qml')
added_files = [
(os.path.join(qml_dir, 'QtQuick'), 'QtQuick'),
(os.path.join(qml_dir, 'QtQuick.2'), 'QtQuick.2'),
]
a = Analysis(['pyqt5_qml.py'],
binaries=None,
datas=added_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='app',
debug=False,
strip=False,
upx=False,
console=True,
)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='pyqt5_qml')
Then try to run pyinstaller
against this spec-file: pyinstaller pyqt5_qml.spec
I hope this could help
I was struggling with the same problem
After hours, I did something simple, but for me it worked
In my main.py I mean the file in which you load the QML file I added
import PyQt5.QtQuick
And then run pyinstaller :
pyinstaller -F - -onefile main.py
And it worked
For me it on Windows this ended up being the QML2_IMPORT_PATH environment variable had not been set. Once I set this to "C:\Python35\Lib\site-packages\PyQt5\qml" it worked!