Search code examples
pythonmatplotlibpyqt4ubuntu-16.04python-3.6

No module named PyQt4 in python 3.6 when I use matplotlib.pyplot


When I import matplotlib.pyplot in any python 3.6 program, I get the following error:

$ python kernel1.py Traceback (most recent call last): File "kernel1.py", line 13, in <module> import matplotlib.pyplot as plt File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module> _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup globals(),locals(),[backend_name],0) File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module> from .backend_qt5 import QtCore File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 26, in <module> import matplotlib.backends.qt_editor.figureoptions as figureoptions File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module> import matplotlib.backends.qt_editor.formlayout as formlayout File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 56, in <module> from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore File "/home/atul/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module> from PyQt4 import QtCore, QtGui ModuleNotFoundError: No module named 'PyQt4'

However, if I use python 3.5, matplotlib.pyplot works perfectly.

I have tried using sudo apt-get install python-qt4. Still I get the same error.

I am using Ubuntu 16.04.


Solution

  • You need to downgrade to PyQt4 from PyQt5 at the command line within the relevant environment:

    conda install pyqt=4
    

    This will downgrade other packages as well. You may need to think about using PyQt5 if this will cause you other problems when using Python 3.6.

    Also, Continuum do not support this version for Python 3.6+. Please see this GitHub page for confirmation.