0

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.

2
  • From the error message that I see that you are using anaconda so install pyqt4 with apt-get does not work, you must use anaconda to install pyqt4 Commented Sep 18, 2017 at 14:34
  • read this: stackoverflow.com/questions/21637922/… Commented Sep 18, 2017 at 14:36

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

For python 3.6(since i had that in my computer), you go to command line , and type this :

conda install -c anaconda pyqt=5.6.0

If you are unsure about the python and pyqt version. Then type :

conda info pyqt

This will output the relevant pyqt version. Hence you can check your pyqt version and install from command mentioned at first.

1 Comment

After I install this, I get the following error: $ python Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib.pyplot as plt [1] 5177 segmentation fault (core dumped) python
0

One command saved me:

conda update ipython

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.