Intent of this post is to document early efforts to get peartree, my library for generated directed network graphs based on public transit schedule data into graph-tool. What is graph-tool? It’s a high-performance C++ library in which core graph algorithms are implemented with an eye towards speed. As a result, computation-intensive network graph calculations can be executed quickly. The library also features Python bindings, enabling a more convenient interface between the existing peartree graph network product and graph-tool’s C++-based model.
This post is intended to be a precursor to a post I am writing on how to convert a NetworkX graph into a graph-tool graph.
Why a blog post?
Setting up graph-tool can be difficult! While the author provides Docker images that enable a user to get up and running with, say, a notebook fairly quickly I wanted to document how I got the tool set up within the development environment I use for peartree.
The TL;DR is that I’m running Python 3.6 on Debian. I believe the image the author publishes is on Alpine. Regardless, I did not find I could easily/satisfactorily port the peartree development environment. As a result, I wanted to get my development environment as close as I could to conforming with a distribution of the graph-tool C library as possible.
To do so, I made sure I was using Debian Stretch. This allowed me to use the Stretch distribution of the library that the author publishes.
With that, I was able to update my
sources.list file with that distribution’s address:
At this point, the author, in the installation instructions, informs the user to verify the packages with the following public key:
During the installation process, I was prompted with a different public key, this one associated with an Ubuntu keyserver (shown below).
I suspect both keys are valid, but in either case navigating this step was fairly straightforward and the prompts made executing the command a matter of cutting and pasting.
Having verified the source, I was able to then update
apt-get and install graph-tool for Python 3:
Once install, I was able to confirm that the files were present, under
/usr/lib/python3/dist-packages/. Because the rest of the Python 3 files were located under
/usr/local/lib/python3.6/site-packages (see below for what current paths were), I need to add to the available system paths the new path (under
At this point, I could drop into a Python 3 REPL and import most components of graph-tool. But, in order to render graphs, I needed a few more libraries, specifically:
- PyCairo, a Python-bindings library for the Cairo graphics tool (so also Cairo)
- PyGraphviz a Python-bindings library for the Graphviz network dot graph rendering tool (so also Graphviz)
I believe Cairo was already installed but, regardless, it’s fairly straightforward to install:
And the Python bindings were installed easily with
The peartree Makefile already contains a script for installing Graphviz and its Python bindings. Its installation is also straightforward:
At this point, the peartree development environment has been “upgraded” sufficiently to support operation of graph-tool (and rendering of graph components). Hopefully this documentation is not just helpful in documenting my efforts with regards to peartree, but also others attempting to install graph-tool on their own in the future.