简体   繁体   English

无法从 gi.repository 导入模块

[英]Can not import modules from gi.repository

I can not import modules from gi.repository.我无法从 gi.repository 导入模块。 Specifically not Gtk and GObject.特别不是 Gtk 和 GObject。

I experienced this error both on Ubuntu 14.04 LTS and after reinstall also on Linux Mint 17.我在 Ubuntu 14.04 LTS 和在 Linux Mint 17 上重新安装后都遇到了这个错误。

from gi.repository import Gtk, GObject

Results in the 'unresolved reference' warning for the respective modules.导致各个模块出现“未解决的参考”警告。 Interestingly enough my Gtk GUI can be compiled and works perfectly fine.有趣的是,我的 Gtk GUI 可以编译并且运行良好。 Yet, GObject is entirely out of function.然而,GObject 完全脱离了 function。

I tried to work around with altering import statements such as:我试图改变导入语句,例如:

from gi.repository.Gtk import*

Even hard coding the import path via:甚至通过以下方式对导入路径进行硬编码:

sys.path.append('/usr/lib/python2.7/dist-packages/gi')

None of these approaches have solved this frustrating error so far.到目前为止,这些方法都没有解决这个令人沮丧的错误。

I have not found any concluding help or basic info on this issue, neither anywhere on the web nor in Linux forums or here on stackoverflow.我在 web 或 Linux 论坛或 stackoverflow 上都没有找到关于此问题的任何结论性帮助或基本信息。 I am not sure whether this problem lies on the Python or the Linux side of things.我不确定这个问题是出在 Python 还是 Linux 方面。

Can anybody suggest how to solve this issue?有人可以建议如何解决这个问题吗? What additional information do I need to provide eventually.我最终需要提供哪些额外信息。

Thanks!谢谢!

If on a Debian-based system such as Ubuntu, you probably need to install the gir1.2-gtk-3.0 package and other similarly named packages for other libraries. 如果在基于Debian的系统(例如Ubuntu)上,则可能需要为其他库安装gir1.2-gtk-3.0软件包和其他类似命名的软件包。 I don't know what the name of the package would be on Mint, but it's probably something similar. 我不知道Mint上的包装名称是什么,但可能有点类似。

在Wheezy(Debian 7.8)上,安装python3-gi为我解决了这个问题。

I stumbled upon this issue with some old github python examples and it helped for me to add lines:我在一些旧的 github python 示例中偶然发现了这个问题,它帮助我添加了几行:

import gi
gi.require_version("Gtk", "3.0")

reference: https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html参考: https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html

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

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