我在 Windows 机器上使用带有 python 2.7 和 matplotlib 的 Spyder。
我正在尝试运行我的脚本,但出现以下错误:
runfile('C:/Python27/Scripts/python-serial-plot.py', wdir=r'C:/Python27/Scripts')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 601, in runfile
execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 66, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Python27/Scripts/python-serial-plot.py", line 8, in <module>
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gtkagg.py", line 14, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gtk.py", line 36, in <module>
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gdk.py", line 33, in <module>
from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
ImportError: No module named _backend_gdk
我去了后端存储的目录,看不到_backend_gdk
。
我该如何解决这个问题?
您需要更改图形后端以修复此错误。在 Spyder 中你需要去
工具 > 首选项 > IPython 控制台 > 图形 > 图形后端
并在那里选择 Inline
或 Automatic
。
我是一名优秀的程序员,十分优秀!