我正在尝试使用pyinstaller、PyQt5和QML构建一个应用程序(参见下面的文件),使用以下命令。
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)
pyqt5_qml.py 运行正常(打开一个“Hello world!”窗口),但是构建的应用程序报错:module "QtQuick" version 2.4 is not installed
。我猜测该模块未被包含在构建的应用程序中,但我不确定如何告诉 PyInstaller 做到这一点。
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>