1

在我的 Windows 10 机器上,我正在尝试一些简单的新 Qt6 示例,并且基于 QML 的示例对我不起作用。

我正在运行 Python 3.8.6 和虚拟环境

python3 -m venv venv
.\venv\Scripts\Activate.ps1

pyside6 在没有任何警告的情况下安装到 venv

pip install pyside6

和一个使用 QApplication 和 QLabel 的非 QML hello world 示例运行良好(这个:https ://doc.qt.io/qtforpython/tutorials/basictutorial/widgets.html )

这个例子不起作用,取自https://doc.qt.io/qtforpython/tutorials/basictutorial/qml.html

主要.py:

from PySide6.QtWidgets import QApplication
from PySide6.QtQuick import QQuickView
from PySide6.QtCore import QUrl

app = QApplication([])
view = QQuickView()
url = QUrl("view.qml")

view.setSource(url)
view.show()
app.exec_()

视图.qml:

import QtQuick 2.0

Rectangle {
    width: 200
    height: 200
    color: "green"

    Text {
        text: "Hello World"
        anchors.centerIn: parent
    }
}

我收到的尝试运行的消息是:

file:///C:/github/aorcl/python-gui-2/view.qml:1:1: Cannot load library C:\github\aorcl\python-gui-2\venv\lib\site-packages\PySide6\qml\QtQml\WorkerScript\workerscriptplugin.dll: The specified module could not be found.
     import QtQuick
     ^
file:///C:/github/aorcl/python-gui-2/view.qml: Failed to load dependencies for module "QtQml" version 6.0
file:///C:/github/aorcl/python-gui-2/view.qml: Failed to load dependencies for module "QtQuick" version 6.0

我验证并且文件没有丢失,它在那里:

C:\github\aorcl\python-gui-2\venv\lib\site-packages\PySide6\qml\QtQml\WorkerScript\workerscriptplugin.dll

我还缺少什么?

4

2 回答 2

0

我在使用 Python 3.9.1 + Pipenv + Windows 10 + Powershell 时遇到了同样的错误。也许它与系统 PATH 环境变量有关。

然后我尝试使用 venv 和 CMD(不是 Powershell),但使用.env\Scripts\activate.bat而不是.\env\Scripts\Activate.ps1. 它正在工作

于 2021-01-20T09:35:09.747 回答
0

我的环境是Python3.8++ PySide6in 。Pycharmwin10

import QtQuick 2.0改为import QtQuick 6.0. 它正在工作。

于 2021-04-16T16:15:28.693 回答