简体   繁体   English

如何在Ubuntu中为glib安装Python3绑定?

[英]How to install Python3 bindings for glib in Ubuntu?

I am using Python3 on an Ubuntu 12.04 system, and I am writing some small apps to teach myself about using cairo from within Python. 我在Ubuntu 12.04系统上使用Python3,并且正在编写一些小应用程序以自学如何在Python中使用cairo。 In idle3 I find the following: 在idle3中,我发现以下内容:

    >>> import glib
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        import glib
    ImportError: No module named glib

I have used Gtk and cairo on the same setup, and python3-gi and python3-gi-cairo are both installed, and in other respects seem to be working fine. 我已经在相同的设置上使用了Gtk和cairo,并且都安装了python3-gi和python3-gi-cairo,并且在其他方​​面似乎运行良好。 It seems there is something else that is missing, but in spite of several web searches I have not unearthed any clues as to what is wrong here. 似乎还有其他遗漏的地方,但是尽管进行了几次网络搜索,但我还没有发现有关这里出了什么问题的任何线索。

Can someone please point me in the right direction? 有人可以指出正确的方向吗?

For gobject introspection, which is what python3-gi gives you, the proper incantation is this: 对于gobject自省,这是python3-gi给您的,正确的咒语是:

 >>> from gi.repository import GLib

For Cairo, use cairo instead of GLib . 对于开罗,请使用cairo而不是GLib

In general, at least under Linux, the installed gobject introspection typelibs are installed in /usr/lib/girepository-1.0 (or similar). 通常,至少在Linux下,已安装的gobject introspection typelib安装在/usr/lib/girepository-1.0 (或类似文件)中。 The name you use to import is derived straightforwardly from the typelib file name. 用于导入的名称直接来自typelib文件名。

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

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