为什么Python3无法导入gi.repository?

Python2没有遇到同样的问题。
greg@greg-precise:~$ python3

Python 3.2.3 (default, May  3 2012, 15:51:42) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> from gi.repository import Gtk

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named gi.repository

(为了清晰起见添加换行)

1个回答

你应该安装正确的Python 3软件包,这些软件包以python3-开头而不是python-
这样就可以解决问题了:
sudo apt-get install python3-gi

或在您喜欢的程序包管理器中搜索此软件包。


请注意,并非您希望使用的所有内容都可能具备从Python 3中提供的12.04包装所需的全部部件。某些库具有特殊的Python重写,需要安装在Python 3目录中,以便python3-gi能够正确地使用这些绑定。 - dobey