Matplotlib: problem in installation

I am using a virtual environment with python 3.6 in Ubuntu Server, in a old processor (32 bits Intel).

First, I installed matplotlib with the pip utility.
Then, I installed PyQt5 (5.15.2) from source.

Now, I can run Qt apps written in python normally.
However when I try to do in ipython (for python 3.6):

%matplotlib qt5

I obtain the following error:

ImportError:
Could not load requested Qt binding. Please ensure that
PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available,
and only one is imported per session.

Currently-imported Qt library:                              'pyqt5'
PyQt4 available (requires QtCore, QtGui, QtSvg):            False
PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): False
PySide >= 1.0.3 installed:                                  False
PySide2 installed:                                          False
Tried to load:                                              ['pyqt5']

The following libs are installed with my PyQt5:

PACKAGE CONTENTS
Qt
QtCore
QtDBus
QtGui
QtNetwork
QtOpenGL
QtPrintSupport
QtSql
QtTest
QtWidgets
QtXml
_QOpenGLFunctions_2_0
_QOpenGLFunctions_2_1
_QOpenGLFunctions_4_1_Core
pylupdate
pylupdate_main
pyrcc
pyrcc_main
sip
uic (package)

How may I repair my matplotlib installation, if this is the issue?

Make sure that:

imports correctly. Please also make sure that PyQt5, ipython, and Matplotlib are all installed in the same virtual environment.

What version of Matplotlib are you installing? About a year (ish?) ago sip changed how it was imported (and could only be imported as a top-level module after pyqt5 has been imported).

It is hard to say much more than that based on the information provided.

They are all installed in the same virtual environment and the version of matplotlib is:

matplotlib==3.3.3

The snippet of code you gave runs with issues except for the initial if…

The other code to check is

Can you do %debug and walk up the call stack to figure out what is failing? Unfortunately the same code that makes it gracefully fail when the qt bindings are not installed also make it difficult to debug when things are installed incorrectly.

Does it work if you do

In[1] %gui qt

? That should trigger IPython Qt import and input hook setup logic without importing Matplotlib.

Running the % stuff:

%gui qt

ERROR:root:
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available,
    and only one is imported per session.

    Currently-imported Qt library:                              None
    PyQt4 available (requires QtCore, QtGui, QtSvg):            False
    PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): False
    PySide >= 1.0.3 installed:                                  False
    PySide2 installed:                                          False
    Tried to load:                                              ['pyqtdefault', 'pyside', 'pyqt5', 'pyside2']


%debug import_pyqt5()
ipdb> c
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/py/my.py in import_pyqt5()
      4         ImportErrors rasied within this function are non-recoverable
      5         """
----> 6         from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui
      7 
      8         # Alias PyQt-specific functions for PySide compatibility.

ImportError: cannot import name 'QtSvg'

%debug import_pyqt5()

> <string>(1)<module>()

ipdb> next
ImportError: cannot import name 'QtSvg'
None
> <string>(1)<module>()

ipdb> next
--Return--
None
> <string>(1)<module>()

ipdb> next
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
ImportError: cannot import name 'QtSvg'
None
> <string>(1)<module>()

ipdb> next
--Return--
None
> <string>(1)<module>()

ipdb> next
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/py/my.py in import_pyqt5()
      4         ImportErrors rasied within this function are non-recoverable
      5         """
----> 6         from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui
      7 
      8         # Alias PyQt-specific functions for PySide compatibility.

ImportError: cannot import name 'QtSvg'

In [17]:

I solved the problem…
The library corresponding to PyQt5.QtSvg was not installed in my system.

So I did:

sudo apt install libqt5svg5*

to install:

libqt5svg5 - Qt 5 SVG module
libqt5svg5-dev - Qt 5 SVG module development files

Then I recompiled and reinstalled PyQt5 in the virtual environment, and then I was able to do import PyQt5.QtSvg and make graphics with matplotlib

Thank you for your assistance.

Great!

It might be worth raising an issue with IPython to get more informative error messages as to which sub-modules are missing (and sort out why they want QtSvg)?