CentOS中python输入import matplotlib.pyplot提示有错误

在CentOS中安装matplotlib(使用命令yum install python-matplotlib)后,在试图导入pyplot后报错:

Traceback (most recent call last):
  File "", line 1, in
  File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 78, in
    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
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
  File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 11, in
    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 *


你可能感兴趣的:(CentOS中python输入import matplotlib.pyplot提示有错误)