python - 导入 Glib 时出错

标签 python python-3.x importerror glib traceback

当尝试使用 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 正确大写:

from gi.repository import GLib

关于python - 导入 Glib 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31151785/

相关文章:

Python 3 运算符 >> 打印到文件

python - 将 Pandas 与 Spark 结合使用

python - Python 中的相对导入混淆

python - 提取子字符串的上下文 URL

python - 将值从批处理脚本传递给 python 变量

javascript - 在将 CSS 作为最终样式提交之前预览 CSS

python - 导入错误:matplotlib 需要 dateutil;将 matplotlib.pyplot 导入为 plt

python - 如何删除已存在列平均值的列

python - 如何从元组列表中删除重复项但保持原始顺序

python - 子进程无法使用 Pandas 执行文件