我很难理解gi.repository
我在代码中使用了这个结构
from gi.repository import Gtk但是如果我想使用某个组件,我会得到导入错误
我搜索了一些组件,比如GtkSource,Vte,GLib,...
所以我的代码是这样的
from gi.repository import Gtk, GtkSource, Vte, GLib一切正常,但是如果我想添加matplotlib来在我的画布上绘制,我会得到错误
enter code/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_ascii_strncasecmp: assertion `s2 != NULL' failed
from gtk import _gtk
Segmentation fault (core dumped) here如何让matplotlib与gi.repository一起工作?
谢谢
发布于 2011-11-13 22:13:50
这是一个非常好的问题。我担心答案可能是“你不能”。Matplotlib的GTK后端是为PyGTK编写的,GTK的旧式Python绑定。Python包是一种新型的gi.repository绑定。我不知道他们是否可以混合在一起,但你的结果似乎表明他们不能。
发布于 2012-01-14 04:37:15
似乎对Gtk3的支持已经是added recently了。我猜它在主要发行版中可用还需要一段时间。
最好的解决方案是下载并安装最新版本。
为了避免在我的Ubuntu11.10中安装东西,我使用了dowloaded backend_gtk3.py and backend_gtk3agg.py files并直接导入,如下所示:
from gi.repository import Gtk
from matplotlib.figure import Figure
from backend_gtk3agg import FigureCanvasGTK3Agg as FigCanvas我不得不更改backend_gtk3agg.py第6行,其中显示:
import backend_agg使用
from matplotlib.backends import backend_agg,这样它就可以从我的安装中导入模块。到目前为止,它对我是有效的,但我知道这个解决方案不能与matplotlib的不同版本一起工作。
https://stackoverflow.com/questions/8109805
复制相似问题