无法在Python 3.7中导入PyQtChart

2024-09-28 20:53:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以使用pip毫无错误地安装PyQtChart,但是我不能导入它,因为Python(3.7.3)告诉我没有这样的模块。在

我在windows10上使用Anaconda的Python发行版,但是它的PyQt5版本确实很旧。在看到eyllanesc提出的一个问题后,我从Anaconda卸载了PyQt5,并通过pip重新安装(当前的5.13版本)。一切都很好,我的PyQt5是最新版本,导入并运行良好。但是PyQtChart没有导入。我是这样安装的:

OK> pip install --user PyQtChart
Collecting PyQtChart
  Downloading https://files.pythonhosted.org/packages/a2/4c/2bf0482300e6ae407d33fcc098c310de00a86f3ee0755ae5419298e5e5c3/PyQtChart-5.13.0-5.13.1-cp35.cp36.cp37.cp38-none-win_amd64.whl (848kB)
     |████████████████████████████████| 849kB 6.4MB/s
Requirement already satisfied: PyQt5>=5.13 in d:\programdata\anaconda3\lib\site-packages (from PyQtChart) (5.13.1)
Requirement already satisfied: PyQt5_sip<13,>=4.19.19 in d:\programdata\anaconda3\lib\site-packages (from PyQt5>=5.13->PyQtChart) (4.19.19)
Installing collected packages: PyQtChart
Successfully installed PyQtChart-5.13.0
OK> pip list
Package                Version
---------------------- ---------
...
PyQt5                  5.13.1
PyQt5-sip              4.19.19
PyQtChart              5.13.0

当我导入时,我得到一个错误:

^{pr2}$

我还查看了dir(PyQt5),没有用于图表的子模块或组件。在

如何才能正确导入?在

编辑: 如前所述,我已经在寻找其他模块。此代码没有帮助,但已请求。在

import PyQt5
import PyQtChart as qtch
#from PyQt5 import QtChart

d = dir(PyQt5)
for i in d:
    if "chart" in i.lower():
        print(i)

我尝试了多种安装和导入方法,包括建议的方法。Pip3不会安装该模块。在


Tags: 模块pipinfromimport版本packages错误
1条回答
网友
1楼 · 发布于 2024-09-28 20:53:55

必须安装相同版本的PyQt5和PyQtChart:

python -m pip install PyQt5==5.13 PyQtChart==5.13

TL;DR;

PyQt是Qt的包装器,Qt的每个版本都生成.dll/,因此与其他版本不兼容。所以同样的问题转移到了PyQt。在您的例子中,可以观察到PyQt5和PyQtChart库使用不同版本的Qt来生成不兼容。在

另一方面,称为X的模块并不意味着它是使用:import X导入的,对于PyQtChart,应该使用:from PyQt5 import QtChart。在

相关问题 更多 >