gpt4 book ai didi

python - 了解 gi.repository

转载 作者:太空狗 更新时间:2023-10-29 17:42:56 26 4
gpt4 key购买 nike

我无法理解 gi.repository

我在我的代码中使用了这个结构

from gi.repository import Gtk

但是如果我想使用某些组件,我会遇到导入错误

我搜索了一下,发现它适用于某些组件,例如 GtkSource、Vte、GLib,...

所以我的代码是这样的

from gi.repository import Gtk, GtkSource, Vte, GLib

一切正常,但如果我想添加 matplotlib 以在我的 Canvas 上绘图,我会遇到错误

    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 一起工作?

谢谢

最佳答案

好像是对Gtk3的支持added recently .我想它需要一些时间才能在主要发行版中可用。

最好的解决方案是下载并安装最新版本。

作为避免在我的 Ubuntu 11.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。

关于python - 了解 gi.repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com