17

I'm developing an app which has to be 100% compatible on windows and on linux. On linux I have no problems, but on windows I came up with this message: from gi.repository import Gtk ImportError: No module named gi

I installed pygobject, pygtkallinone, gtk.. what am I missing?

Yerko Antonio
  • 657
  • 3
  • 8
  • 16

2 Answers2

20

Most of Havok answer is correct, except that documentation has been improved a lot lately, with a Tutorial:

Including a PDF version for offline reading:

And a complete API reference manual, not only of Gtk but also many other libraries that you can use with introspection:

on windows the support is great, a lot of effort has been put in creating all the windows executables and libraries, the last release of pygi-aio is 3.10.6:

I've also put instructions on the Gnome wiki on how to build on win32 with pygobject introspection, it's not that hard, I've also uploaded a setup.py that actually works:

So the answer is, don't go with PyGTK

tobias47n9e
  • 2,233
  • 3
  • 28
  • 54
gianmt
  • 1,162
  • 8
  • 15
  • 2
    Great answer, thanks. Good to know that many things have improved over the years. – Havok Feb 11 '14 at 18:57
  • Great answer. The version of pygi-aio was even bumped to 3.14 a day ago. – tobias47n9e Feb 28 '15 at 19:27
  • 1
    The files given at `http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar` simply don't work. The installer copy stuff, but no library is loadable by python when using `from gi.repository import Gtk`. – Lærne Nov 13 '15 at 08:56
  • Apparently Python 3.5 isn't supported yet as we can read this in the readme.txt: `PyGI 3.18.2 AIO rev6 for python 2.7, 3.1, 3.2, 3.3 and 3.4 (32bit/64bit)` and `Python 3.5 port is WIP`. – Creak Jul 09 '16 at 04:28
15

gi.repository module is called PyGObject and is for Gtk+3 and is not yet available for Windows (there has been experiments, but is not ready AFAIK). https://live.gnome.org/PyGObject

gtk module is called PyGtk and is for Gtk+2 and is very mature on Windows platforms (in particular 2.24). http://www.pygtk.org/

What's the difference?

  • PyGObject has some scarse Windows support. PyGtk has great support for this OS.
  • PyGObject is what is called a dynamic binding and PyGtk is a static one.
  • PyGObject is new and the future and PyGtk is the past, mature and some day will be deprecated.
  • PyGObject documentation and examples are very very limited, and PyGtk one are very very complete: http://developer.gnome.org/pygtk/stable/
  • They are not compatible, you can't use both and you need to choose one.
  • PyGObject is in active development, no new features will be introduced for PyGtk.
  • If you use Glade, the lastest version will be for PyGObject (for example 3.12.1). If you want to use Glade for PyGtk install the 3.8.0 version.

If you choose to go PyGtk there is great support for freezing the application. You can check my documentation and support files for my application here: http://sourceforge.net/p/nestededitor/code/247/tree/trunk/dist/windows/

Hope it helps.

EDIT:

Many things have changed in two years. Please see gianmt answer.

Havok
  • 5,776
  • 1
  • 35
  • 44
  • are there any problems with freezing PyGTK applications using [PyInstaller](http://www.pyinstaller.org/)? py2exe is Windows only – jfs Oct 20 '12 at 08:59
  • Never tested with PyInstaller, sorry. – Havok Oct 21 '12 at 02:21
  • PyGObject has some documentation, that ain't that bad: http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html – liberforce Oct 22 '12 at 09:29
  • Yes, the documentation is getting better and better, but that's a tutorial, not an API reference. You can't do serious programming in PyGObject without an API reference, because you need to know all the functions, variables, signal, etc, available. Good API documentation is this one http://developer.gnome.org/gtk3/stable/ (for C) or http://developer.gnome.org/pygtk/stable/ (for old PyGtk), PyGObject the best it has now is this http://people.gnome.org/~johnp/girdocsalpha/Gtk/. With time, tools for generation of the documentation will improve and allow to program in PyGObject. – Havok Oct 23 '12 at 00:06
  • Released: January 27, 2013 pygi-3.4.2_gtk+-3.6.4.7z http://opensourcepack.blogspot.de/p/pygobject-pygi-aio.html – Sam Jan 29 '13 at 01:23