Python、Gtk3 和 Gstreamer

Python、Gtk3 和 Gstreamer

这不是一个令人满意的组合,但它在大多数情况下确实有效。然而,我刚刚遇到了 Gio.File 的问题。这将始终导致 TypeError 和 Python 段错误:

Python 2.7.3 (default, Apr 10 2012, 12:29:04) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import GObject, Gio
>>> import gst
>>> la = Gio.File.new_for_path("/home/dklasinc/foo")

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
ERROR:/build/buildd/pygobject-3.2.0/gi/_gobject/pygobject.c:929:pygobject_new_full: assertion failed: (tp != NULL)

有办法解决这个问题吗?我想使用 Gio 进行文件复制操作,以便我可以向用户提供一些反馈。

答案1

你使用的是哪个版本的 Ubuntu?此时,你实际上不应该能够将 PyGI 与任何旧的静态 pygobject 内容一起使用。如果这有效,那几乎是偶然的。无论如何,在 Precise 上,如果导入的顺序被反转,你会得到一个解释该问题的异常:

>>> import gst
>>> from gi.repository import GObject, Gio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 23, in <module>
    from ._gi import _API, Repository
ImportError: could not import gobject (error was: ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".',))

作为一种解决方法,您可以让您的 UI 调用一个辅助脚本,并在该脚本中仅使用静态 gst/gobject 内容吗?

尽管仍处于非常前沿的阶段,GStreamer 1.0 完全支持 PyGI。Quantal 中有软件包,Precise 也有可用的反向移植。请参阅我的GStreamer 1.0 Python 移植指南

答案2

您不能将 Gobject 自省与静态 GStreamer 绑定结合起来,否则会导致崩溃和问题。您还需要对 GStreamer 使用自省,而这实际上仅在 0.11/1.0 版本中受支持。

相关内容