在我的Windows10机器上,我尝试了几个新的基于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的例子:
main.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_()
view.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
我还漏掉了什么?
发布于 2021-01-20 17:35:10
我在使用Python 3.9.1 + Pipenv + Windows 10 + Powershell时也遇到了同样的错误。可能与系统PATH环境变量相关。
我尝试使用venv和CMD (不是Powershell),但使用.env\Scripts\activate.bat
而不是.\env\Scripts\Activate.ps1
激活环境。它起作用了
发布于 2021-04-17 00:15:29
我的环境是win10
中的Python3.8
+ PySide6
+ Pycharm
。
我将import QtQuick 2.0
更改为import QtQuick 6.0
。起作用了。
https://stackoverflow.com/questions/65426701
复制相似问题