[英]PyQt5: module “QtCharts” is not installed
I'm trying to use QtCharts from QML in a PyQt5 app.我正在尝试在 PyQt5 应用程序中使用来自 QML 的 QtCharts。
Qt5 is installed via HomeBrew, and the QtCharts module appears to be installed (unless when called via PyQt5 it looks somewhere else): Qt5 是通过 HomeBrew 安装的,并且 QtCharts 模块似乎已安装(除非通过 PyQt5 调用它看起来在其他地方):
$ ls -1 /usr/local/opt/qt5/qml/QtCharts
designer
libqtchartsqml2.dylib
plugins.qmltypes
qmldir
In PyQt5, I can run a QtQuick app without problems, but if I try to import QtCharts 2.2
I get an error:在 PyQt5 中,我可以毫无问题地运行 QtQuick 应用程序,但如果我尝试
import QtCharts 2.2
,则会出现错误:
module "QtCharts" is not installed
未安装模块“QtCharts”
Minimal testcase that exhibits this problem:显示此问题的最小测试用例:
test_qml_qtcharts.py 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())
Output: Output:
$ python3 test_qml_qtcharts.py
QQmlComponent: Component is not ready
main.qml:3:1: module "QtCharts" is not installed
Removing import QtCharts 2.2
the test runs fine.删除
import QtCharts 2.2
测试运行良好。
I was wrong assuming it would look into the system's Qt5 installation.假设它会查看系统的 Qt5 安装,我错了。
Solution: install PyQtChart via pip:解决方案:通过 pip 安装 PyQtChart:
python3 -m pip install PyQtChart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.