How to install pygraphviz on windows

4,965 views
Skip to first unread message

Ffederico Vaggi

unread,
Feb 23, 2011, 9:50:19 AM2/23/11
to networkx-discuss
I put together a small list on instructions required to install
pygraphviz on windows - I couldn't find all the information together
in one place, so perhaps this can be useful to other people:

1- Download the latest version of pygraphviz from:

http://networkx.lanl.gov/download/pygraphviz/

2- Download the latest version of graphviz from:

http://www.graphviz.org/Download_windows.php

3- Unzip pygraphviz to an easy location.

4- Open up setup.py in pygraphviz:

In line 31 and 32, edit:

library_path=r'C:\Program Files (x86)\Graphviz2.26.3\lib\debug\lib'
include_path=r'C:\Program Files (x86)\Graphviz2.26.3\include\graphviz'

or wherever you installed graphviz on your machine

5- Go down to line 107, where the compiler extensions are defined and
change it to this:

extension = [Extension("pygraphviz._graphviz",
["pygraphviz/graphviz_wrap.c"],
include_dirs=include_dirs,
#library_dirs=library_dirs,
#runtime_library_dirs=library_dirs,
extra_link_args=["/LIBPATH:"+library_path],
libraries=["cgraph","cdt"],
)]

basically comment out library_dirs and run_time_library, and add the
extra_link_args parameter

6- If you have developer studio 2008, you can now install it. Switch
to the directory, and type:

python setup.py install

and it should install relatively painlessly.

7- If you do have developer studio 2010, you'll find that your version
isn't compatible - you need either mingGW or visual studio 2008. I
found minGW gives a lot of errors so install visual studio 2008. If
you use minGW, you have to revert the changes you made to extension at
point 5.

At this point, I am sure all the Linux users are feeling very smug
about how 'easy to use' Windows is :p These instructions were
sufficient to install it on two different machines though, one xp and
one windows 7.

Ffederico Vaggi

unread,
Feb 23, 2011, 10:12:17 AM2/23/11
to networkx-discuss
I should of course add - this installs the software fine, but it seems
like random crashes when using pygraphviz are still common. Importing
is ok though!
Message has been deleted

Marc-Olivier Titeux

unread,
Feb 25, 2011, 7:24:17 PM2/25/11
to networkx...@googlegroups.com
Thanks for the tip. 

Can I assume you have either Visual 2008 or MingW32 installed on your machine?
Please, could you detail how you setup the linker for pygraphviz? 

I have tried with Visual 2005 and I get a "Error: Unable to fin vcvarsall.bat (because of Python-2.7 version I guess).
I also have Ming32 installed. So I setup a distutils.cfg in Python27/Lib/distutils with:

[build]
compiler=mingw32 

As mentionned on this link for a similar problem. But 'easy_install pygraphviz' does not succeed this way. I attached the compilation log (with --verbose option). I suspect that I have an version issue between pygraphviz, python and MingW32. But, if you could let me know what is your setup, that would be great.

Thanks a lot!
Marc-Olivier

PS EDIT: removed "only" with Visual
compilationLog-pygraphviz.txt

Tony Theodore

unread,
Feb 25, 2011, 8:30:39 PM2/25/11
to networkx...@googlegroups.com, Marc-Olivier Titeux
On 26 February 2011 11:24, Marc-Olivier Titeux

I wonder if it's a mismatch between 32-bit graphviz (C:\Program Files
(x86)\Graphviz2.26.3) and 64-bit python?

Cheers,

Tony

Reply all
Reply to author
Forward
0 new messages