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 http://pypi.python.org/simple/pygraphviz/
Reading http://networkx.lanl.gov/pygraphviz
Reading http://networkx.lanl.gov/wiki/download
Reading http://sourceforge.net/project/showfiles.php?group_id=122233&package_id=161979
Reading http://networkx.lanl.gov/download
Best match: pygraphviz 0.99.1
Downloading http://pypi.python.org/packages/source/p/pygraphviz/pygraphviz-0........
Processing pygraphviz-0.99.1.zip
Running pygraphviz-0.99.1/setup.py -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 setup.py 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 setup.py 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 setup.py 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/__init__.py -> build/lib.macosx-10.4-i386-2.5/pygraphviz
copying pygraphviz/agraph.py -> 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("file.dot")

 

Share/Bookmark






3 Responses to “Installing PyGraphviz [tested on OSx Leopard]”

thanks !

felix added these pithy words on Sep 19 12 at 10:59 am

Thanks. and if you’re using virtualenv, are those the same path you’re going to put in there ?

Stockman added these pithy words on Aug 06 13 at 8:17 am

Thank you very much!

I still get an error message after I run python setup.py install:

4 warnings generated.

gcc -bundle -undefined dynamic_lookup -L/Users/filippperesadilo/anaconda/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/pygraphviz/graphviz_wrap.o -L/usr/local/lib/graphviz -L/usr/local/lib/graphviz -lcgraph -lcdt -o build/lib.macosx-10.5-x86_64-2.7/pygraphviz/_graphviz.so

ld: library not found for -lcgraph

clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: command ‘gcc’ failed with exit status 1

Any idea about what is going on?

Thanks in advance!

Peter added these pithy words on Dec 13 13 at 4:49 pm