Home > Blockchain >  PyQt5 Missing QtQuick.Studio Module
PyQt5 Missing QtQuick.Studio Module

Time:11-11

Issue

I used Qt Design Studio to create some UI components and screens (.ui.qml format), but no matter what I do, whenever I try to run it in PyQt5 I kept encountering the following error:

module "QtQuick.Studio.Components" is not installed

The .ui.qml file has an import

import QtQuick.Studio.Components 1.0

I looked everywhere online and couldn't find much on the topic on how to fix this problem.

Question

What's the best way to overcome this issue? I've been using it on Windows but I am mainly looking to use the code on a raspberry pi, are there extra dependencies that need to be installed?

Python code

import os
from pathlib import Path
import sys

from PyQt5.QtCore import QCoreApplication, Qt, QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine

if __name__ == '__main__':

    CURRENT_DIRECTORY = Path(__file__).resolve().parent

    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.addImportPath(os.fspath(CURRENT_DIRECTORY.parents[0]))
    url = QUrl.fromLocalFile(os.fspath(CURRENT_DIRECTORY / "Screen01.ui.qml"))

    def handle_object_created(obj, obj_url):
        if obj is None and url == obj_url:
            print("exit")
            QCoreApplication.exit(-1)

    engine.objectCreated.connect(
        handle_object_created, Qt.ConnectionType.QueuedConnection
    )

    engine.load(url)

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec())

CodePudding user response:

Windows

I used print(engine.importPathList()) to see my import paths. This prompted me to go C:/Users/USER/AppData/Local/Programs/Python/Python38/lib/site-packages/PyQt5/Qt5/qml and noticed that QtQuick exists but does not have a Studio folder.

Since Qt Design Studio can run my code with no import issues, I knew that it would have a Studio folder. Therefore, I went into C:\Program Files\Qt\qtdesignstudio-2.2.0-community\qt5_design_studio_reduced_version\qml\QtQuick and copied the Studio folder from there onto the PyQt5 path above.

This fixed the issue.

Linux

I am yet to try it on Linux.

  • Related