[英]Understanding gi.repository
I have troubles understanding gi.repository 我很难理解gi.repository
I use this contruction in my code 我在我的代码中使用了这个结构
from gi.repository import Gtk
But if I want to use some component I get import error 但如果我想使用某些组件,我会导致导入错误
I searched and I got it worked for some components, like GtkSource, Vte, GLib, ... 我搜索了一下,我得到了一些组件,比如GtkSource,Vte,GLib,......
So my code is like 所以我的代码就像
from gi.repository import Gtk, GtkSource, Vte, GLib
Everything worked fine, but if I want to add matplotlib to draw on my canvas I get and error 一切都运行正常,但如果我想添加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
How can I get matplotlib working with gi.repository? 如何让matplotlib使用gi.repository?
Thank you 谢谢
It seems that the support for Gtk3 it's been added recently . 似乎最近添加了对Gtk3的支持。 I guess it will take some time till it's available in the main distributions.
我想它需要一些时间,直到它在主要发行版中可用。
The best solution would be to download and install the latest version. 最好的解决方案是下载并安装最新版本。
As a workaround to avoid installing stuff in my Ubuntu 11.10 I have dowloaded backend_gtk3.py and backend_gtk3agg.py files and imported directly like: 作为避免在我的Ubuntu 11.10中安装东西的一种解决方法,我已经下载了backend_gtk3.py和backend_gtk3agg.py文件并直接导入,如:
from gi.repository import Gtk
from matplotlib.figure import Figure
from backend_gtk3agg import FigureCanvasGTK3Agg as FigCanvas
I had to change backend_gtk3agg.py line 6 where it says: 我不得不改变backend_gtk3agg.py第6行,它说:
import backend_agg
with 同
from matplotlib.backends import backend_agg
, so it can import the module from my installation. ,所以它可以从我的安装中导入模块。 So far it works for me, but I understand this solution can't work with different versions of matplotlib.
到目前为止它对我有用,但我知道这个解决方案不能用于不同版本的matplotlib。
That's a very good question. 这是一个非常好的问题。 I'm afraid the answer might be "you can't."
我担心答案可能是“你做不到”。 Matplotlib's GTK backend is written for PyGTK, the old-style Python bindings for GTK.
Matplotlib的GTK后端是为PyGTK编写的,这是GTK的旧式Python绑定。 The gi.repository package is the new-style Python bindings.
gi.repository包是新式的Python绑定。 I don't know one way or the other whether they can mix or not, but your results seem to indicate they can't.
我不知道他们是否可以混合,但你的结果似乎表明他们不能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.