简体   繁体   中英

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.

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.

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.

一个命令救了我:

conda update ipython

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM