Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using Ubuntu 12.04 with python 2.7.3 and PyGObject and I'd like to develop plugins for Gedit in python. I found a simple looking tutorial for this sort of thing here.

According to the tutorial, I need the Gedit module to interact with the plugin interface:

from gi.repository import GObject, Gedit

I keep getting an import error when trying to import the Gedit module. So, my question is: what package do I need to install to get this module?

I've tried: gedit-dev , gedit-plugins

Edit: Here is the full traceback for the above statement:

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
share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

To answer your question, the typelib you need for developing gedit plugins is contained in the gedit package itself.

$ apt-file search Gedit-3.0.typelib
gedit: /usr/lib/gedit/girepository-1.0/Gedit-3.0.typelib

But when using python either interactively or from a script, from gi.repository import Gedit searches /usr/lib/girepository-1.0/ rather than /usr/lib/gedit/girepository-1.0. That is the cause of the import error.

You'll need to create the appropriate .plugin and .py files in ~/.local/share/gedit/plugins and run your code by selecting the plugin in the gedit preferences dialog.

share|improve this answer
add comment

I get the same error as you if I run the plugin code directly without Gedit.

As it is described in the manual you linked, you need to make a .plugin file for your plugin code. Place your plugin code and the .plugin file into ~/.local/share/gedit/plugins. Restart Gedit. Open Gedit > Edit > Preferences > Plugins and look for your plugin. Set the checkmark for your plugin. Your plugin shoud run now using the Gedit code.

To check for errors in your plugin, start gedit from a console.

share|improve this answer
add comment

An import error for Gedit may indicate that GtkSource-3.0.typelib is missing or not installed correctly.

Typical symptoms are in addition that you can't load several plugins (not only the one you develop yourself), and that you get warnings when starting gedit from the command line (seen on Ubuntu 13.10 Saucy). You can fix this by installing the missing package:

sudo apt-get install gir1.2-gtksource-3.0

See also: Warnings while launching gedit from the Ubuntu terminal

Also note that the plugins for GEdit v3 use python3 instead of version 2.7.x of Python.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.