Monday, May 23, 2011

Installing Gtk+3 And PyGobject Introspection


In an earlier post, I assumed the latest version of Gtk+3 and PyGI would be installed by default on Ubuntu 11.04. However, as I discovered some methods were missing (Gdk.atom_intern()), it became evident I did not have the latest versions of the above libraries.


Warning: Some of the packages of Gtk+3 or its dependencies may be experimental. After I installed Gtk+3  and PyGI, I had major issues with Gnome and had to reinstall Ubuntu altogether. I am not sure about the relation between installing Gtk+3, PyGI and the problem I had, but you are warned and should do that at your own risk.

Now Gtk+ offers an installation guide. The installation process is not only cumbersome, but the guide here above is not well written in my opinion. Also, the dependencies of Gtk+3 have their own dependencies and it's a never ending pain to get through it. Depending on your distribution though, the process may be easier on you. For instance if you are using Gentoo, you may simply have to
USE=introspection emerge gtk+.


I'm using Ubuntu 11.04 however and i'll be able to document just that. If you have any other information about other distributions, let me know and i'll update this post.


Step 1: Checking Dependencies
A number of libraries are necessary for Gtk+3 to function. These are the latest versions of:
  • Glib
  • Pango
  • Atk
  • GNU libiconv
  • GNU gettext
  • fontconfig
  • Cairo
  • GdkPixbuf
  • Gobject-Introspection
  • shared-mime-info
Some of those packages may already be installed on 11.04 (in this epic installation I've lost track of what was already installed by default). You can get some from your repositories easily and others you want to install the latest versions available on line.

Installing Glib
You can get the latest version of Glib from ftp and install it:

./configure
make
make install
NB: the configuration script will install the configuration file to /usr/lib/i386-linux-gnu/pkgconfig which may be a problem to other installations. If a further configuration script says it cannot find the latest Glib library, you ought to:

export PKG_CONFIG_PATH="/usr/lib/i386-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"
before running the configuration script again.

Installing Pango
You can get the latest version of Pango from ftp too and perform the same configure, make, make install operation. You can alternatively install the library from repositories:

sudo apt-get install libpango1.0*


Installing Atk
I had a hard time installing this one. First the ftp was not available and second the packages I found failed to install. Luckily Atk is available from repositories:

sudo apt-get install libatk1.0*


Installing GNU Libiconv And Gettext
I couldn't find those in repositories, correct me if i'm wrong. Get the latests vertions of Libiconv and Gettext from ftp. Repeat the configure-make-install process and it should work.

Installing Fontconfig
Fontconfig is available from respositories:

sudo apt-get install fontconfig


Installing Cairo
Get the latest release from ftp, config-make-install takes some time, but it worked smoothly for me.

Installing Gdk-Pixbuf
I believe this is one of those I didn't have to install. You can always check:

sudo apt-get install libgdk-pixbuf2.0*


Installing Gobject Introspection
This is what will allow PyGobject Introspection to do its job. Simply:

sudo apt-get install gobject-introspection


Installing Share Mime Info
I secretly skipped this one, but you can get it here, and it wouldn't surprise me if it was in the repository as well.

Step 2: Installing Gtk+3
With all the above dependencies we should be set. Download Gtk+3's latest version, as of this post it's 3.10 already. Before run the configuration, you want to do:

export PKG_CONFIG_PATH="/usr/lib/i386-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"
Otherwise it won't find the latest GLIB version you just installed. Then go for:

./configure
make
make install
It went fine that way for me and I hope it went well for you.

Step 3: Installing PyGobject Instrospection
The documentation will tell you about the latest version of PyGobject, as of this post it is the 2.28. Configure, make, make install, if necessary set the PKG_CONFIG_PATH again before configuration.
Once you did that you still need to update your Gobject Introspection Repository. There are plenty of packages which you can find with:

apt-cache search gir1.2-
You may not need to install everything, definitely:

sudo apt-get install gir1.2-gtk-3.0 gir1.2-gdk-3.0 gir1.2-gdkpixbuf-2.0

Now you should be all set for making some Gtk+3 GUI with Python  :)

2 comments:

  1. Hi,
    you need to do a few more steps to make it work in gentoo:

    - edit /usr/portage/profiles/base/use.mask and comment out 'introspection' line in there

    - now you are able to emerge pygobject with 'introspection' flag, so do it

    ReplyDelete
  2. The procedure can be carried out in Ubuntu 11.04. However, a program cannot be compiled using python3.2.
    The demo applications from the gnome site do not compile and run

    ReplyDelete