【问题标题】:Error Importing Glib导入 Glib 时出错
【发布时间】:2015-07-01 02:48:37
【问题描述】:

当尝试使用from gi.repository import glib 在 python 3 中导入 glib 时,我收到一条错误消息:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2135, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/gi/importer.py", line 53, in find_module
    'introspection typelib not found' % namespace)
ImportError: cannot import name glib, introspection typelib not found

我在 Ubuntu 14.04 上使用 apt-get 安装了所有 python glib/dev 包。尝试在 python 2 中导入模块表示该模块不存在。

我该如何解决这个问题?

【问题讨论】:

  • 你能展示你的代码吗?
  • 一到导入语句就会抛出一个错误。我试过使用交互式解释器,这就是它抛出错误的地方。
  • 有趣。请问你是怎么安装glib的?

标签: python python-3.x importerror glib traceback


【解决方案1】:

GLib 正确大写对我有用:

from gi.repository import GLib

【讨论】:

  • 嗯,这行得通。奇怪,我看到多个网站用不同的大写字母拼写它说它有效。
  • @Kookerus 也许你把它和旧式的import glib混淆了?
  • 也许我复制它的网站有。我见过from gi.repository import glibfrom gi.repository import Glib
  • 快速的 Google 搜索显示了很多 from gi.repository import Glibfrom gi.repository import GLib as glib。反正很容易混淆。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-05
  • 2012-10-28
相关资源
最近更新 更多