我開始深入瞭解使用pyGTK +與python和matplotlib交互繪圖。所以我看了一下example given at the matplotlib website。ImportError:沒有名爲_backend_gdk的模塊
這是代碼的短exerpt:
#!/usr/bin/env python
"""
Example of embedding matplotlib in an application and interacting with
a treeview to store data. Double click on an entry to update plot
data
"""
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk
import matplotlib
matplotlib.use('GTKAgg') # or 'GTK'
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from numpy.random import random
from matplotlib.figure import Figure
那些我嘗試在終端我碰到下面的錯誤運行此腳本:
Traceback (most recent call last):
File "gtk_spreadsheet.py", line 15, in <module>
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 33, in <module>
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_gdk.py", line 29, in <module>
from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
ImportError: No module named _backend_gdk
我有蟒蛇2.7和PyGTK的2.24安裝。
任何人都可以找出錯誤的位置?我認爲這可能與一些鏈接問題有關?
你是怎麼安裝matplotlib的? '_backend_gdk'是一個需要編譯的c-python擴展。 – tacaswell
如果matplotlib已經編譯好了,yoo可以從matplotlib單獨編譯它嗎?我通過終端從源碼構建matplotlib。 – Gjan
很可能,但正確連接它需要複製setup.py所具有的深層魔法。 – tacaswell