简体   繁体   English

在KDE上为Python导入Gtk typelib

[英]Importing Gtk typelib for Python on KDE

I have written a GUI application in python making use of Gtk. 我已经使用Gtk在python中编写了GUI应用程序。 Unfortunately I had to move to a new OS and absolutely have to use its KDE desktop. 不幸的是,我不得不迁移到新的操作系统,并且绝对必须使用其KDE桌面。

Now python can not import any of the submodules from gi.repository, despite python-gi being installed and up to date: 现在,尽管已安装python-gi并保持最新状态,但python无法从gi.repository导入任何子模块:

from gi.repository import Gtk, GObject, GLib

It seems to be a general problem on Linux, that any submodule references of gi.repository can not be resolved but strangely enough the python GUI was still executable and ran flawlessly on all Gnome systems (Ubuntu, Lubuntu, Linux Mint) I tested it on. 在Linux上这似乎是一个普遍的问题,无法解析gi.repository的任何子模块引用,但奇怪的是python GUI仍然可执行并且可以在所有Gnome系统(Ubuntu,Lubuntu,Linux Mint)上完美运行。 。

Not so on KDE. 在KDE上不是这样。 Running the code yields the following error: 运行代码会产生以下错误:

ERROR:root:Could not find any typelib for Gtk
Traceback (most recent call last):
  File "folder/Program.py", line 2, in <module>
    from gi.repository import Gtk, GObject, GLib
ImportError: cannot import name Gtk

I am a bit lost how to overcome this error. 我有点不知道如何克服这个错误。 I think I have to install some Gtk system packages/typelib, but which? 我想我必须安装一些Gtk系统软件包/ typelib,但是哪个?

Could not find anything on the web. 在网络上找不到任何内容。

Any suggestions are warmly welcome! 任何建议都热烈欢迎!

Info: I am running on Debian Wheezy with KDE. 信息:我正在使用KDE在Debian Wheezy上运行。

The answer differs per distribution; 每个分配的答案有所不同。 for instance, on Debian/Ubuntu-based systems, you have to install gir1.2-gtk-[23].0 depending on which GTK+ version you want to target as well as the appropriate libgtk*-dev for that version. 例如,在基于Debian / Ubuntu的系统上,您必须安装gir1.2-gtk-[23].0具体取决于要定位的GTK +版本以及该版本的相应libgtk*-dev (At least I think; I'm not sure if they both need to be installed for Python or not...). (至少我认为;我不确定是否都需要为Python安装它们……)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM