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

前端之家收集整理的这篇文章主要介绍了CentOS中python输入import matplotlib.pyplot提示有错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在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

猜你在找的CentOS相关文章