Today I used matplotlib to draw a picture and found that it could not be drawn, and an error was reported
import matplotlib.pyplot as plt
File "D:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "D:\Anaconda3\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import QtCore
File "D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 31, in <module>
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
File "D:\Anaconda3\lib\site-packages\matplotlib\backends\qt_compat.py", line 137, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named 'PyQt4'
ok, then I will check, there is a way like this
import matplotlib as mpl
mpl.use(‘Agg’)
No error was reported this time, but no picture at all
I thought about it, printed out the backend and found it was Qt5Agg
import matplotlib
# import matplotlib.pyplot as plt
backend = matplotlib.get_backend()
print(backend)
I want to give it a try, because I have done something similar before
I probably know that there are "TkAgg", "WXAgg", "Qt5Agg", other types have not been exposed
Just try to change it, the result is "TkAgg"
import matplotlib
# import matplotlib.pyplot as plt
backend = matplotlib.get_backend()
print(backend)
matplotlib.use('TkAgg')
So don’t worry about installing this and that when you encounter this problem