无法在 Python 3.7 中导入 PyQtChart [英] Cannot import PyQtChart in Python 3.7

查看:69
本文介绍了无法在 Python 3.7 中导入 PyQtChart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am able to install PyQtChart without error using pip, but I cannot import it as Python (3.7.3) tells me there is no such module.

我在 Windows 10 上使用 Anaconda 的 Python 发行版,但它的 PyQt5 版本真的很旧.在看到 eyllanesc 提出的带有评论的问题后,我从 Anaconda 卸载了 PyQt5 并通过 pip 重新安装了(当前的 5.13 版本).一切正常,我的 PyQt5 是最新版本,可以导入并且运行良好.但是 PyQtChart 没有导入.我是这样安装的:

I'm using Anaconda's Python distribution on Windows 10, but its version of PyQt5 is really old. After seeing a question with a comment by eyllanesc I uninstalled PyQt5 from Anaconda and reinstalled (the current 5.13 version) via pip. Everything with that worked fine and my PyQt5 is the latest version and imports and works well. But PyQtChart isn't importing. I installed like this:

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

当我导入时出现错误:

ModuleNotFoundError: No module named 'PyQtChart'

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

I also looked through the dir(PyQt5) and there is no submodule or component for charts.

如何才能正确导入?

正如我所提到的,我已经在寻找其他模块.此代码没有帮助,但请求.

As I mentioned, I already looked for other modules. This code is not helpful, but requested.

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 不会安装该模块.

I TRIED multiple ways to install and import, including the suggested ways. Pip3 would not install the module.

推荐答案

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

You have to have the same version of PyQt5 and PyQtChart installed:

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

<小时>

TL;博士;

PyQt 是 Qt 的封装,每个版本的 Qt 都会生成 .dll/.so,与其他版本不兼容.所以同样的问题转移到 PyQt.在您的情况下,观察到 PyQt5 和 PyQtChart 库使用不同版本的 Qt 产生不兼容性.

PyQt is a wrapper of the Qt, and each version of Qt generates .dll/.so that are not compatible with other versions. So that same problem moves to PyQt. In your case it is observed that the PyQt5 and PyQtChart libraries use different versions of Qt generating incompatibility.

另一方面,称为 X 的模块并不意味着它是使用:import X 导入的,在 PyQtChart 的情况下,您应该使用:from PyQt5 import QtChart.

On the other hand that a module is called X does not imply that it is imported using: import X, in the case of PyQtChart you should use: from PyQt5 import QtChart.

这篇关于无法在 Python 3.7 中导入 PyQtChart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆