Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#40179 closed defect (invalid)

Can't import gi.repository after installing gtk3

Reported by: istlota@… Owned by: macports-tickets@…
Priority: Normal Milestone:
Component: ports Version: 2.2.0
Keywords: Cc: neverpanic (Clemens Lang)
Port: gtk3

Description (last modified by ryandesign (Ryan Carsten Schmidt))

After failing to get gtk3 to work, as a hail mark pass, I completely uninstalled MacPorts per section 2.5 of the guide, then reinstalled MacPorts from the source tarball. After that, I only port installed two ports: python27 and gtk3 +x11. That worked without any reported problems. I then coded this simple program which ran okay, but note that it does not use the new gobject-introspection Way of doing things with gtk3:

import gobject
from gobject import GObject

class MyClass(GObject):
    prop = gobject.property(type=int)

def cb(sender, prop):
    print "property '%s' changed on %r." % (prop.name, sender)

inst = MyClass()
inst.connect("notify", cb)
inst.prop = 42

Next, I coded the following program which does use the gobject-introspection Way. But it fails indicating an import error for the 'from gi.repository import GObject' statement. Why does installing the gtk3 port on my mac end up with python not being able to find gi.repository?

from gi.repository import GObject


class MyClass(GObject.GObject):

    prop = GObject.property(type=int)


def cb(sender, prop):
    print "property '%s' changed on %r." % (prop.name, sender)

inst = MyClass()
inst.connect("notify", cb)
inst.prop = 42

Change History (6)

comment:1 Changed 11 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: cal@… added
Description: modified (diff)
Keywords: gi.repository removed

Remember to use WikiFormatting when writing in Trac. I'm Cc'ing the maintainer of gtk3; maybe he knows the answer to your question.

comment:2 Changed 11 years ago by neverpanic (Clemens Lang)

Resolution: invalid
Status: newclosed

You probably want the py27-gobject3 port.

comment:3 in reply to:  2 ; Changed 11 years ago by istlota@…

Replying to cal@…:

You probably want the py27-gobject3 port.

Thanks. It continues to amaze me how promptly MacPorts support responds to opened tickets, especially considering that I opened this ticket on a Sunday.

'port installed' confirmed that py27-gobject was installed instead of py27-gobject3. And, after I installed py27-gobject3, I am now able to correctly 'from gi.repository import Gtk'. But, note, we are still left with my initial question unanswered. Ergo, why did installing the gtk3 port on my mac end up with python not being able to find gi.repository?

Note that I began by uninstalling MacPorts, then reinstalled it from the source tarball and only installed two ports [python27 and gtk3 +x11]. Which means gtk3 incorrectly installed py27-gobject when it needed to install py27-gobject3 to operate properly. To be more specific, gtk3 installed at-spi2-atk as a dependency, which installed dbus-python27 as a dependency, which installed p27-gobject as a dependency.

Is this one of those catch-22s the entire industry is having to just accept for now due to having two Ways of binding Python to GTK [GTK2 and PyGtk vs. GTK3 and PyGObject] which can and often do break each other when both are used on the same machine? Or, can the gtk3 portfile, perhaps, be modified to install the appropriate flavor of gobject3 [py27-gobject3 in my case] as a dependency?

comment:4 in reply to:  3 Changed 11 years ago by neverpanic (Clemens Lang)

Replying to istlota@…:

Thanks. It continues to amaze me how promptly MacPorts support responds to opened tickets, especially considering that I opened this ticket on a Sunday.

I just happened to be at doing MacPorts-related stuff anyway.

Replying to istlota@…:

Ergo, why did installing the gtk3 port on my mac end up with python not being able to find gi.repository?

The software installed by the gtk3 port does not need the python bindings from py27-gobject3. This is also the reason why there is no dependency from gtk3 to py27-gobject3 (also: if there was, which version of python should we depend on? There is py{26,27,31,32,33}-gobject3).

Replying to istlota@…:

Which means gtk3 incorrectly installed py27-gobject when it needed to install py27-gobject3 to operate properly. To be more specific, gtk3 installed at-spi2-atk as a dependency, which installed dbus-python27 as a dependency, which installed p27-gobject as a dependency.

First: gtk3 does not need py27-gobject3 to operate properly. Dependent software that uses the python bindings for Gtk might, but that software should declare a dependency on py27-gobject3 then.

I don't know (despite being the maintainer for this port) why at-spi2-atk needs dbus-python27. dbus-python27 needs a dependency on py27-gobject (the gtk2 version), because it uses an old API provided by py27-gobject (but I just noticed the relevant file ./dbus/gobject_service.py in the dbus-python27 sources also supports using py27-gobject3). You could file a bug requesting to change the dependency to py27-gobject3 instead of py27-gobject. But even this won't solve your original issue, because gtk3 -x11 +quartz doesn't pull in at-spi2-atk and thus doesn't have a transitive dependency on py27-gobject3.

Replying to istlota@…:

Is this one of those catch-22s the entire industry is having to just accept for now due to having two Ways of binding Python to GTK [GTK2 and PyGtk vs. GTK3 and PyGObject] which can and often do break each other when both are used on the same machine?

How do PyGtk and PyGObject break each other? I haven't noticed any problems with running both versions simultaneously.

Replying to istlota@…:

Or, can the gtk3 portfile, perhaps, be modified to install the appropriate flavor of gobject3 [py27-gobject3 in my case] as a dependency?

As explained above, this is not the correct way to fix this. Dependent software needs to depend on py*-gobject3 if it needs the Gtk Python bindings. If you need them for a project outside MacPorts I'm afraid you will have to install them manually.

comment:5 Changed 11 years ago by istlota@…

I see more clearly now why py27-gobject3, from a maintainer's perspective, should not be a dependency of gtk3. Still, from a user's perspective, his gtk3 code will need to import Gtk from gi.repository. Am I correct that py27-gobject3 is what creates my gi.repository dynamic binding from python to gtk3?

comment:6 in reply to:  5 Changed 11 years ago by neverpanic (Clemens Lang)

Replying to istlota@…:

Am I correct that py27-gobject3 is what creates my gi.repository dynamic binding from python to gtk3?

Partially, yes. py27-gobject3 provides the gi.repository to import from. What can be imported from gi.repository depends on what GObject-Introspection typelibs are available in /opt/local/lib/girepository-1.0/. The GObject typelib is created by the gobject-introspection port; other typelibs might be installed by different ports: e.g., the Gtk-3.0 typelib is installed by the gtk3 port.

Note: See TracTickets for help on using tickets.