我试图在一个QtCharts应用程序中使用QML中的PyQt5。
Qt5是通过HomeBrew安装的,并且似乎安装了QtCharts模块(除非通过PyQt5调用时它看起来在其他地方):
$ ls -1 /usr/local/opt/qt5/qml/QtCharts
designer
libqtchartsqml2.dylib
plugins.qmltypes
qmldir在PyQt5中,我可以运行一个没有问题的QtQuick应用程序,但是如果我试图运行import QtCharts 2.2,就会得到一个错误:
没有安装
模块"QtCharts“
显示此问题的最小测试案例:
test_qml_qtcharts.py
import sys
from PyQt5.QtCore import QCoreApplication, QUrl
from PyQt5.QtQml import QQmlComponent, QQmlEngine
app = QCoreApplication(sys.argv)
engine = QQmlEngine()
component = QQmlComponent(engine)
component.setData(b'''
import QtQuick 2.9
import QtCharts 2.2
Item {}
''', QUrl('main.qml'))
instance = component.create()
if not instance:
for error in component.errors():
print(error.toString())输出:
$ python3 test_qml_qtcharts.py
QQmlComponent: Component is not ready
main.qml:3:1: module "QtCharts" is not installed删除import QtCharts 2.2测试运行良好。
发布于 2021-01-29 23:08:21
我认为它会调查系统的Qt5安装是错误的。
解决方案:通过pip安装PyQtChart:
python3 -m pip install PyQtCharthttps://stackoverflow.com/questions/65962902
复制相似问题