Installing PyGraphviz [tested on OSx Leopard]

PyGraphviz is a Python interface to the Graphviz graph layout and visualization package. With PyGraphviz you can create, edit, read, write, and draw graphs using Python to access the Graphviz graph data structure and layout algorithms.

[I was doing this in order to benefit from some of the django-command-extension functionalities]

1. Get graphviz here and install it (should be straightforward)

2. Download PyGraphViz. Make sure you download the source package. It's possible to install it through easy_install but it would throw the following error:

bash-3.2$ easy_install pygraphviz Searching for pygraphviz Reading Reading Reading Reading Reading Best match: pygraphviz 0.99.1 Downloading Processing Running pygraphviz-0.99.1/ -q bdist_egg --dist-dir /var/folders/Cm/C......... Trying pkg-config /bin/sh: pkg-config: command not found /bin/sh: pkg-config: command not found Trying dotneato-config Failed to find dotneato-config

Your graphviz installation could not be found.

Either the graphviz package is missing on incomplete (binary packages graphviz-dev or graphviz-devel missing?).

If you think your installation is correct you will need to manually change the include_path and library_path variables in to point to the correct locations of your graphviz installation.

The current setting of library_path and include_path is: library_path\=None include_path\=None

error: None

3. Change by specifying where your graphViz installation is [more info here]:

# library_path=None library_path\='/usr/local/lib/graphviz' # include_path=None include_path\='/usr/local/include/graphviz'

4. Install:

bash-3.2$ python install library_path\=/usr/local/lib/graphviz include_path\=/usr/local/include/graphviz running install running build running build_py creating build/lib.macosx-10.4-i386-2.5 creating build/lib.macosx-10.4-i386-2.5/pygraphviz copying pygraphviz/ -> build/lib.macosx-10.4-i386-2.5/pygraphviz copying pygraphviz/ -> build/lib.macosx-10.4-i386-2.5/pygraphviz [...... etc. etc.......]

5. Enjoy!:

>>> import pygraphviz as pgv >>> G\=pgv.AGraph() >>> G.add_node('a') >>> G.add_edge('b','c') >>> G strict graph { a; b -- c; }

To load a dot file use

>>> G\=pgv.AGraph("")

Cite this blog post:

Michele Pasin. Installing PyGraphviz [tested on OSx Leopard]. Blog post on Published on Oct. 14, 2009.


See also: