After I had installed graph-tool and gtk+3 via homebrew and tried to run a graph-tool demo, I came across the following problem:
1 2 3 4 5 6 7 8 9 |
Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/graph_tool/draw/cairo_draw.py", line 868, in graph_draw nodesfirst, **kwargs) File "/usr/local/lib/python2.7/site-packages/graph_tool/draw/gtk_draw.py", line 950, in interactive_window nodesfirst, update_layout, **kwargs) File "/usr/local/lib/python2.7/site-packages/graph_tool/draw/gtk_draw.py", line 880, in __init__ os.path.dirname(__file__)) GError: Couldn't recognize the image file format for file '/usr/local/lib/python2.7/site-packages/graph_tool/draw/graph-tool-logo.svg' |
I then did a little bit Googling and found out that this was caused by a lack of SVG lib ‘librsvg’ for homebrew’s gtk installation. However, a simple homebrew installation of that lib didn’t fix the problem. Lucky, I found this. It says that we need to refresh the gdk-pixbuf-query-loaders in order for gtk to recognise librsvg. Unfortunately, if you use homebrew’s librsvg (2.36.3), you will come across another problem:
1 2 3 |
g_module_open() failed for /usr/local/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: dlopen(/usr/local/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so, 10): Library not loaded: /usr/local/lib/librsvg-2.2.dylib Referenced from: /usr/local/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so Reason: Incompatible library version: libpixbufloader-svg.so requires version 43.0.0 or later, but librsvg-2.2.dylib provides version 39.0.0 |
Yes, we need to compile the newest librsvg:
1. Download librsvg-2.40.2 source code from here
2. Configure, make and install librsvg as follows:
1 2 3 |
$ ./configure --disable-Bsymbolic --disable-inspection PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig/:/usr/X11/lib/pkgconfig" $ make $ make install |
Note that you may have to install more libs, such as libxml2, via homebrew.
3. Refresh gdk-pixbuf-query-loaders to load librsvg for gtk:
1 2 |
$ export GDK_PIXBUF_MODULEDIR=/usr/local/lib/gdk-pixbuf-2.0/2.10.0/loaders $ gdk-pixbuf-query-loaders --update-cache |
4. Enjoy graph-tool