16 Ocak 2012 Pazartesi

pygraphviz on windows (Python 2.7)

Installing pygraphviz on Windows is a lit bit tricky.. It took almost all my sunday afternoon to find out a solution that works for me.. Finally i did by following instructions on http://blog.ropardo.ro/2011/11/28/installing-pygraphviz-on-windows/ 


Here is my steps:
  1. Install ActivePython Community Edition (http://www.activestate.com/activepython) in order to have easy_install. Add PYTHON_HOME/Scripts folder to PATH variable.
  2. Install required/wanted Python packages with easy_install. However, pygraphviz do not have a Windows build, and it can not be easy installed, since Python does not know where Graphviz is installed..
  3. Install Graphviz (http://www.graphviz.org/
  4. Installed an old version of MinGW (specifically the build on 20100831) (http://www.mingw.org/) . Add MinGW/bin to PATH.
  5. Download pygraphviz (http://networkx.lanl.gov/pygraphviz/) and extract it.
    1. Edit setup.py of pygraphviz as follows:     (they are None as default..)
      • library_path="C:/Graphviz 2.28/lib/release/lib"
      • include_path="C:/Graphviz 2.28/include/graphviz" 
    2. Modify line 285 (most probably) from “C:\python27\lib\distutils\unixcompiler.py" as follows:
      • old:  compiler = os.path.basename(sysconfig.get_config_var("CC"))
      • new: compiler =  "gcc" 
    3. Run the following command from pygraphviz-$version folder:
      • python setup.py build -c mingw32
    4. Copy the pygraphviz folder under (some place like) C:\pygraphviz-1.1\build\lib.win32-2.7 to Python site-packages.My site-packages location is  C:\Python27\Lib\site-packages.
After the steps above, import pygraphviz should succeed on Python interpreter..

The link which i presented in the beginning of this post worked for me.. However, some slightly different solutions exist (unfortunately, they did not help much my condition):




3 yorum:

  1. Hi,

    I could not find the MinGW build 20100831 from the link. I installed the latest version of MinGW, and follow all the steps and failed.

    the error message was:

    C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files\Graphviz 2.28\include\graphviz"
    -Ic:\Python27\include -Ic:\Python27\PC -c pygraphviz/graphviz_wrap.c -o build\temp.win32-2.7\Release
    \pygraphviz\graphviz_wrap.o
    cc1.exe: error: unrecognized command line option '-mno-cygwin'
    error: command 'gcc' failed with exit status 1

    May you please direct me to the link which I could download the build?

    thanks

    -John

    YanıtlaSil
  2. this link seems alive:
    http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20100831/

    YanıtlaSil
  3. Thanks, this helped greatly.

    I also had to make this edit in order to build Django UML graphs, because of the spaces in paths in Windows:

    agraph.py, line 1249 in _run_prog():
    runprog = '"' + runprog + '"'

    YanıtlaSil