kazam 失败并显示“PyGIWarning:Gtk 已导入但未先指定版本...”

Gau*_*mar 4 pygtk kazam python3

安装kazam投屏软件后,无法启动。

我使用的是 Ubuntu 17.04。

更新: 在此输入图像描述

    /usr/bin/kazam:32: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk
/usr/lib/python3/dist-packages/kazam/frontend/window_area.py:30: PyGIWarning: Wnck was imported without specifying a version first. Use gi.require_version('Wnck', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Gtk, GObject, Gdk, Wnck, GdkX11
/usr/lib/python3/dist-packages/kazam/backend/gstreamer.py:35: PyGIWarning: Gst was imported without specifying a version first. Use gi.require_version('Gst', '1.0') before import to ensure that the right version gets loaded.
  from gi.repository import GObject, Gst
/usr/lib/python3/dist-packages/kazam/frontend/indicator.py:148: PyGIWarning: AppIndicator3 was imported without specifying a version first. Use gi.require_version('AppIndicator3', '0.1') before import to ensure that the right version gets loaded.
  from gi.repository import AppIndicator3
/usr/lib/python3/dist-packages/kazam/frontend/indicator.py:97: PyGIWarning: Keybinder was imported without specifying a version first. Use gi.require_version('Keybinder', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import Keybinder
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)

Mes*_*ion 5

只需安装即可python3-xlib解决您使用 Kazam 的特定分段错误问题,但您可能已经注意到仍然存在一些有关“未先指定版本”导入的 PyGI 警告。

由于这个问题是谷歌关于此类警告的#1(这就是我在这里偶然发现的),因此这就是如何更改代码以防止此类警告,如警告本身所述。

代替:

from gi.repository import Gtk, GObject, Gdk, Wnck, GdkX11, Gst, AppIndicator3
Run Code Online (Sandbox Code Playgroud)

它会发出几个警告:

from gi.repository import Gtk, GObject, Gdk, Wnck, GdkX11, Gst, AppIndicator3
Run Code Online (Sandbox Code Playgroud)

根据PyGOobject 官方文档,使用它:

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Wnck', '3.0')
gi.require_version('Gst', '1.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk, GObject, Gdk, Wnck, GdkX11, Gst, AppIndicator3
Run Code Online (Sandbox Code Playgroud)

显然并非所有的gi子模块都需要指定版本。

或者,您可以使用该require_versions()函数(注意复数)在单个语句中要求所有版本,该函数采用模块及其各自版本的单个字典:

import gi
gi.require_versions({
    'Gtk':  '3.0',
    'Wnck': '3.0',
    'Gst':  '1.0',
    'AppIndicator3': '0.1',
})
from gi.repository import Gtk, GObject, Gdk, Wnck, GdkX11, Gst, AppIndicator3
Run Code Online (Sandbox Code Playgroud)

该函数并未在官方文档中列出,但在 2016 年发布的PyGObject 3.21.0中添加了该函数。