我将 Ubuntu 12.04 与 python 2.7.3 和 PyGObject 一起使用,我想在 python 中为 Gedit 开发插件。我在这里找到了有关此类事情的简单教程。
根据教程,我需要Gedit模块与插件界面交互:
from gi.repository import GObject, Gedit
Run Code Online (Sandbox Code Playgroud)
尝试导入 Gedit 模块时,我不断收到导入错误。所以,我的问题是:我需要安装什么包才能获得这个模块?
我试过:gedit-dev,gedit-plugins
编辑:这是上述语句的完整回溯:
ERROR:root:Could not find any typelib for Gedit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name Gedit
Run Code Online (Sandbox Code Playgroud)
为了回答您的问题,开发 gedit 插件所需的 typelib 包含在 gedit 包本身中。
$ apt-file search Gedit-3.0.typelib
gedit: /usr/lib/gedit/girepository-1.0/Gedit-3.0.typelib
Run Code Online (Sandbox Code Playgroud)
但是,当以交互方式或从脚本使用 python 时,from gi.repository import Gedit会搜索/usr/lib/girepository-1.0/而不是/usr/lib/gedit/girepository-1.0. 这就是导入错误的原因。
您需要在 ~/.local/share/gedit/plugins 中创建适当的 .plugin 和 .py 文件,并通过在 gedit 首选项对话框中选择插件来运行代码。