Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import PyQtChart in Python 3.7

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.

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

and when I import I get the error:

ModuleNotFoundError: No module named 'PyQtChart'

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

How can get this to import properly?

EDIT: 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)

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

like image 636
Gene Avatar asked Apr 14 '26 18:04

Gene


1 Answers

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

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

TL; DR;

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.

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.

like image 190
eyllanesc Avatar answered Apr 16 '26 08:04

eyllanesc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!