'Error importing Gtk module: No module named repository' with graph_tool

2.6k views Asked by At

Hello stack community!

I'm not sure if my question is graph-tool related or gtk-related, but maybe both. Moreover, sorry if what I did while trying to solve it is plain stupid, I'm not a programmer by formal education, so I know just as much as I could find by google and comprehend.

Here is the problem: After I brew install graph-tool, launch python and try to import graph_tool.all I get the following error:

/usr/local/lib/python2.7/site-packages/graph_tool/draw/cairo_draw.py:1318: RuntimeWarning: Error importing Gtk module: No module named repository; GTK+ drawing will not work.

Previously I was sure that if import pygtk; pygtk.require('2.0'); import gtk works, that means the error is a graph-tool issue, but that don't have to be the case since graph-tool might use gtk (3??) and GObject (right?) and the upper checks for gtk2 and pygtk ( This question led me to this thought ). I tried reinstalling gtk, GObject and all dependencies. Wipe all brew-related and brew itself and then reinstall everything (as in here). Still same error appears. I also tried to unlink everything from brew and link it again just to be sure, but this does not change anything either.

What else did I check:

I'm running MAC OS X Version 10.10.3, homebrew-installed python 2.7.10 (python --version returns Python 2.7.10 which is the one installed by brew; which python points to /usr/local/bin/python). brew info graph-tool shows that all requirements of it are there (even the optional ones). GTK 2.24.28, GTK+3 3.16.4, PyGobject 2.28.6, GObject-introspection 2.28.6, Cairo 1.14.2, Py2Cairo 1.10.0, pango 1.36.8, XQuartz 2.7.7 etc are installed, dependencies of those are fine as well. gi 1.2 is installed (via pip), gi.repository is indeed not there. I am aware of this question, but I have PyGObjects installed.

I also read this question and the reply, but none of this solves my problem as far as I can judge.

I've spend two days looking for the solution, so any help is appreciated.

2

There are 2 answers

2
Fabrício On

I've faced the same issue (with a slight difference on the line number):

>>> from graph_tool.all import *
/usr/local/lib/python2.7/site-packages/graph_tool/draw/cairo_draw.py:1499: RuntimeWarning: Error importing Gtk module: No module named gi; GTK+ drawing will not work.
  warnings.warn(msg, RuntimeWarning)

I know it's a relatively old question but wanted to share how I did it. You said you tried reinstalling GObject, but that is what made it work here.

I followed the installing instructions

brew install pygobject3 --with-python@2 gtk+3

which said gtk+3 and pygobject3 were already installed. Then I ran:

brew reinstall gtk+3

and

brew upgrade pygobject3

which made the import work.

2
A. STEFANI On

It's seem to be a cairo dependency issue.

As you may see here, graph-tool package require a lot of depencies (numpy, gfortran, scipy, freetype, libpng, matplotlib, boost, cgal, graphviz, cairo, cairomm, py2cairo)

In your case you may probably solve the issue with a clean reinstall of "cairo".

Try those commands:

brew install cairo
brew install cairomm
brew install py2cairo

If "brew" ask you to run command or install other packages, do it !

(We assume here that "brew" is properly installed)

Best regards