问题
I'm trying to get a basic PyQt5 QML project going using either Windows or Linux. I first tried Linux and with no luck am trying Windows now. My issue is whenever I try and run it via python main.py it will complain that "module "QtQuick" is not installed" and "module "QtQuick.Window" is not installed".
I feel like this is a simple pointing of some path to the QT install location but don't know where to go from here. Using Qt Widgets works but not QML.
My main.py file is:
import sys
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtGui import QGuiApplication
def _find_plugins():
import PyQt5
from os import path
paths = [path.abspath(path.join(path.dirname(PyQt5.__file__), 'plugins'))]
import PyQt5.QtCore
PyQt5.QtCore.QCoreApplication.setLibraryPaths(paths)
if __name__ == '__main__':
# _find_plugins()
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load('test.qml')
sys.exit(app.exec_())
and my test.qml file is:
import QtQuick 2.2
import QtQuick.Window 2.1
ApplicationWindow {
visible: true
width: 640
height: 480
minimumWidth: 400
minimumHeight: 300
}
回答1:
Turns out I needed to add the following Environment Variable:
QML2_IMPORT_PATH
with the value in my case being:
C:\Python35\Lib\site-packages\PyQt5\qml
来源:https://stackoverflow.com/questions/37843212/pyqt5-module-qtquick-is-not-installed