在CentOS中安装matplotlib(使用命令yum installPython-matplotlib)后,在试图导入pyplot后报错:
Traceback (most recent call last):
File "<stdin>",line 1,in <module>
File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py",line 78,in <module>
new_figure_manager,draw_if_interactive,show = pylab_setup()
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/__init__.py",line 25,in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py",line 10,in <module>
from matplotlib.backends.backend_gtk import gtk,FigureManagerGTK,FigureCanvasGTK,\
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py",line 11,in <module>
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
此时可以这样解决:
import matplotlib
matplotlib.use('Agg')
from matplotlib.pyplot import *
原文链接:https://www.f2er.com/centos/377260.html