Python under Win is really a pain!
For English users, please ignore the next paragraph and jump to the process part directly.
process: python2.6(enthought)+networkx(1.0 rc1)+pygraphviz(0.99.1) under windows xp sp3
When you proceed, please first try to install without my modification, because some bugs might have been fixed when you see this post.
1. Have python2.6 and mingw32 installed. I’m using enthought, which is the company that sponsors scipy. The academic version is FREE. For beginners like me, creating python tool chain from scratch (download python, scipy, numpy, matplotlib … separately) is really a frustrating process.
2. Install the “setuptools”(0.6c11.1) here http://pypi.python.org/pypi/setuptools#files, so that you can use easy_install. You can skip this step if you want to install networkx manually.
3. Install “networkx”(1.0rc1) using the command: “easy_install networkx”
4. Install “graphviz”(2.26.3) (yes, pygraphviz is just a python interface to graphviz, so you need to install graphviz first). You can’t install pygraphviz using easy_install, because it depends on graphviz, and the easy_install too can’t find the path of graphviz. So you need to download and install “graphviz” from here: http://www.graphviz.org/Download_windows.php
5. Install pygraphviz from source:
5.1 Download pygraphviz(0.99.1) from this link http://networkx.lanl.gov/pygraphviz/download.html, and extract it.
5.2 Modify “setup.py”
5.3 Modify “c:\python26\lib\distutils\unixcompiler.py”, (for me it was line 282):
compiler = os.path.basename(sysconfig.get_config_var("CC"))
compiler = "gcc"
Otherwise there would be an error “TypeError: ‘NoneType’ object is unsubscriptable”, see this link “http://code.google.com/p/netcdf4-python/issues/detail?id=8”. I change it back after finishing installing pygraphviz for safety (I am a beginner).
5.4 Run command “python setup.py install” under the pygraphviz source directory. Now you should be able to install it.
6. Now the installation is done, but if you try to run the sample code such as edge_colormap, you might get an error: “close_fds is not supported on Windows platforms, balabala”. This was a bug of pygraphviz, I found it here and here. So I followed the links and modified line 1146 of site-packages/pygraphviz/agraph.py to
7. Now you should be able to run the test codes without error and begin to do your own work. Actually, my python crashes when I run the test codes “circular_tree” and “lanl_routes”. I don’t know why and really don’t want to spend time fixing it.
I hope those issues will be fixed soon so nobody have to follow this painful process. Working with python under windows is really a pain.