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.

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.

Gene
  • 97
  • 2
  • 7
  • show your .py . Although the module is called PyQtChart that does not imply that it should be imported using that name, I recommend testing the following code: https://stackoverflow.com/a/56727642/6622587 or https://stackoverflow.com/a/50548931/6622587 – eyllanesc Oct 07 '19 at 17:10
  • A friend of mine had this problem, try using pip3 instead of pip – bogus Oct 07 '19 at 17:13
  • @bogus I think the installation is correct but is importing it incorrectly. The correct import is `from PyQt5 import QtChart` – eyllanesc Oct 07 '19 at 17:14
  • @Gene Do not use `import PyQtChart as qtch` but `from PyQt5 import QtChart` as the examples I have attached show. – eyllanesc Oct 07 '19 at 18:30
  • @eyllanesc, Thank you, but I tried that as well: ImportError: cannot import name 'QtChart' from 'PyQt5' (C:\Users\geneb\AppData\Roaming\Python\Python37\site-packages\PyQt5\__init__.py). I'm wondering if it has something to do with that init file. – Gene Oct 07 '19 at 18:48
  • 1
    try install PyQt5 5.13: `python -m pip install PyQt5==5.13` – eyllanesc Oct 07 '19 at 18:51
  • Yes, that seems to have worked. I did that and then reinstalled PyQtChart as well using the same syntax and it ran. You should make that an answer. Why did that work? – Gene Oct 07 '19 at 19:06
  • You might also consider using [pyqtgraph](http://pyqtgraph.org/) which is a completely different project that has excellent [documentation](http://pyqtgraph.org/documentation/) and many built-in examples. – bfris Oct 07 '19 at 20:43

2 Answers2

7

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
0

For me: only "pip install PyQtChart" this update PYQT5 and install module PyQt5.QtChart