错误:导入 gi 失败。

3
这是我尝试运行的命令及其输出:
$ python2
Python 2.7.8 (default, Sep 24 2014, 18:26:21) 
[GCC 4.9.1 20140903 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: /usr/lib/python2.7/site-packages/gi/_gi.so: undefined symbol: g_type_check_instance_is_fundamentally_a

我已经搜索了这个错误,但是没有找到任何有用的信息。

这些是我安装的包:

$ pacman -Qs python
local/pygtk 2.24.0-3
    Python bindings for the GTK widget set
local/python 3.3.4-1
    Next generation of the python high-level scripting language
local/python-dbus-common 1.2.0-2
    Common dbus-python files shared between python-dbus and python2-dbus
local/python-gobject 3.14.0-2
    Python 3 bindings for GObject
local/python-gobject2 2.28.6-11
    Python 3 bindings for GObject2
local/python2 2.7.8-2
    A high-level scripting language
local/python2-cairo 1.10.0-1
    Python2 bindings for the cairo graphics library
local/python2-dbus 1.2.0-2
    Python 2.7 bindings for DBUS
local/python2-distutils-extra 2.38-1
    Enhancements to the Python build system
local/python2-gobject 3.14.0-2
    Python 2 bindings for GObject
local/python2-gobject2 2.28.6-11
    Python 2 bindings for GObject2
local/python2-pillow 2.3.0-3
    Python Imaging Library (PIL) fork. Python2 version.
local/python2-xdg 0.25-1
    Python library to access freedesktop.org standards

我不知道我错过了什么...

已解决:

错误是由于较早版本的glib2软件包引起的。

1个回答

5
这可能不是Python问题,也不是您的代码问题。 /usr/lib/python2.7/site-packages/gi/_gi.so 可能已经损坏或编译错误。也许您把它放在了错误的路径下。 解决方法:升级glib2。

@AadityaBagga 你可能需要卸载所属的'_gi.so'包,并从官方网站或使用pip重新安装它;如果这不起作用,下载源代码并自行编译。 - ForceBru
这个包是python2-gobject,我刚刚安装了它,不确定重新安装是否会有任何区别。 - abchk1234
1
@AadityaBagga '未定义的符号' 是关于 _你的系统_,而不是 Python。python2-gobject 可能依赖于某些未安装的软件包。 - ForceBru
Python2-gobject的依赖项已安装,因为软件包管理器会自动解决依赖关系。也许有未列出的依赖项? - abchk1234
搞定了:升级glib2包解决了它;)感谢指点,将其标记为已解决;您可能需要编辑您的帖子以包含此信息。 - abchk1234

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接