After importing with pip: %matplotlib qt throws ImportError. Should I just install pyqt5 manually or is this unexpected behavior?

I have been using mpl for years, installing with conda, and in my ipython contexts, have had no issues with the magic %matplotlib qt. Today I’m working in a new environment using pip and after installing matplotlib, the same magic command yielded:

ImportError: Failed to import any of the following Qt binding modules: PyQt6, PySide6, PyQt5, PySide2

Is this expected behavior when installing with pip, perhaps to give us more freedom to choose our GUI front end? If so, when creating a package and setting dependencies in my pyproject.toml should I specify so my users don’t end up in such problems? Currently I have:

dependencies = [

I got rid of the error with pip install PyQt5 would it be a good idea for me to add “pyQt5” (or whatever) to the above dependency list? I’m sort of in new territory here as I’ve been using conda for many years. Is there a standard route I’m missing here, or maybe is what I’m seeing not expected behavior?

If you conda install matplotlib, you get pyqt automatically, but it is not a dependency of Matplotlib. So yes, if you use pip and you want pyqt then you need to explicitly add it.

1 Like

Ah thank you this makes sense, I will split my package into core/visualization modules and include optional dependencies like matplotlib/pyqt5 for the viz module.