PyInstaller + PyQt5 + QML: QtQuick not installed

I am trying to create an application using pyinstaller, PyQt5 and qml (see files below) using the following command.

pyrcc5 pyqt5_qml.qrc > pyqt5_qml_qrc.py
pyinstaller -w -F --noupx pyqt5_qml.py

(OSX 10.11.1, python 3.5.0, qt 5.5.1, pyinstaller 3.0)

The pyqt5_qml.py file works fine (open the "Hello world!" Window), but the embedded application complains module "QtQuick" version 2.4 is not installed. I think the module was not included in the embedded application, but I'm not sure how to tell pyinstaller to do this.

pyqt5_qml.py:

import os, sys
from PyQt5 import QtCore, QtWidgets, QtQml
import pyqt5_qml_qrc

def main():
    global app 
    app = QtWidgets.QApplication(sys.argv)
    engine = QtQml.QQmlApplicationEngine()
    engine.load(QtCore.QUrl('qrc:/hello.qml'))
    root = engine.rootObjects()[0]
    root.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

hello.qml:

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1

ApplicationWindow {
    title: qsTr("Window")
    Rectangle {
        width: 360
        height: 360
        Text {
            anchors.centerIn: parent
            text: "Hello World"
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                Qt.quit();
            }
        }
    }
}

pyqt5_qml.qrc:

<!DOCTYPE RCC><RCC version="1.0">
<qresource>
    <file>hello.qml</file>
</qresource>
</RCC>
+4
source share
3 answers

Windows, , QML2_IMPORT_PATH . "C:\Python35\Lib\site-packages\PyQt5\qml", !

0

PyInstaller , QML, . , , QtQuick QtQuick.2 python (<your_python_path>\Lib\site-packages\PyQt5\Qt\qml) :

QtQuick
QtQuick.2
your_executable.exe

, .spec (pyinstaller .spec ).

# -*- 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')

pyinstaller spec : pyinstaller pyqt5_qml.spec

0

,

- ,

main.py , QML,

import PyQt5.QtQuick

pyinstaller:

pyinstaller  -F  - -onefile main.py

And it worked

0
source

Source: https://habr.com/ru/post/1617792/


All Articles