0

I am new to python and trying to run a program with Gtk on Python 3.4 and Windows 7.

I installed Python 3.4, the GTK+ all-in-one-bundle for Windows and PyGObject (which your are apparently supposed to use with Python 3+ now).

However, I am always getting the same error when trying to import Gtk:

C:\>python -c "from gi.repository import Gtk"

The error is

ERROR:root:Could not find any typelib for Gtk
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'Gtk'

Is there any essential step I am missing? I could not find any information on that problem, most advice is unix-related and advises people to install this or that debian package. (Which does not help me much on a Win 7 machine.)

magnattic
  • 12,638
  • 13
  • 62
  • 115
  • Did you install the bundle into a place where python looks for it? – drahnr May 12 '14 at 21:21
  • I added the \bin folder of GTK+ to the PATH variable, if that's what you mean. – magnattic May 12 '14 at 21:25
  • That is not enough, how should python find the libraries which are used by the introspection bindings? You need to pass that information on via an ENV variable (don't know which one, but this should give you an idea what is missing). – drahnr May 12 '14 at 22:17
  • Yes, thank you. I think I found it (see my answer below). For some reasons most tutorials left that part out... – magnattic May 12 '14 at 22:20

1 Answers1

0

I finally got it to work by adding an environment variable named "GTK_BASEPATH" pointing to the GTK+ main folder and reinstalling PyGObject with all packages that looked useful to me.

My guess is that Python was unable to find GTK+ without the basepath, but I have tried so many things that I can not know for sure if that was the reason why it finally worked.

Here is a description of how to set the system variable under Windows.

magnattic
  • 12,638
  • 13
  • 62
  • 115