我在Windows机器上使用Spyder和python 2.7以及matplotlib。
我正在尝试运行我的脚本,我收到以下错误:
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
。
如何解决此问题?
答案 0 :(得分:0)
您需要更改图形后端以修复此错误。在Spyder你需要去
Tools > Preferences > IPython console > Graphics > Graphics backend
然后在那里选择Inline
或Automatic
。
答案 1 :(得分:-1)
您可以切换后端以列出所有后端:
In [5]: import matplotlib
In [6]: matplotlib.rcsetup.all_backends
然后使用matplotlib.use('some_backend')
选择另一个,我不使用Windows,所以不能推荐使用什么,但你可以尝试不同的,看看什么效果最好。
matplotlib.use('some_backend')
应该在任何import matplotlib.pyplot
等语句之前