【问题标题】:PyQt5: module "QtCharts" is not installedPyQt5:未安装模块“QtCharts”
【发布时间】:2021-01-29 23:07:30
【问题描述】:

我正在尝试在 PyQt5 应用程序中使用 QML 中的 QtCharts。

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 测试运行正常。

【问题讨论】:

    标签: python qt pyqt5 qml qtcharts


    【解决方案1】:

    假设它会查看系统的 Qt5 安装,我错了。

    解决方案:通过 pip 安装 PyQtChart:

    python3 -m pip install PyQtChart
    

    【讨论】:

    • 我也面临同样的问题。即使在 pip 安装之后,问题仍然存在。如果我遗漏了什么,请告诉我。提前致谢。
    猜你喜欢
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 2021-12-07
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    相关资源
    最近更新 更多