Just For Fun

李亚普诺夫斯基的混乱天堂

Python under Win is really a pain!

leave a comment »

For English users, please ignore the next paragraph and jump to the process part directly.

想用python实现几个图论的小算法,发现了networkx和pygraphviz两个库,在archlinux下很容易地就用easy_install安装了这两个库,并且很顺利地运行了http://networkx.lanl.gov/gallery.html下面的一些测试程序。昨晚想在笔记本的xp上演示一下,于是找对应的windows版,本以为也可以用easy_install轻松装好,没想到问题一大堆,折腾的过程就不说了,就说一下怎么解决的吧,看了这个过程就知道在win下开发python有多麻烦了。

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”

library_path='c:/Program Files/Graphviz2.26.3/lib/release/lib'
include_path='c:/Program Files/Graphviz2.26.3/include/graphviz'

5.3 Modify “c:\python26\lib\distutils\unixcompiler.py”, (for me it was line 282):

change
compiler = os.path.basename(sysconfig.get_config_var("CC"))
to
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

close_fds=False)

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.

Written by Jerry

February 12, 2010 at 12:45 am

Posted in techniclick

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: