Monday, 27 May 2013

Python - Install PyGraphviz on Windows

Download
http://www.graphviz.org/Download_windows.php
https://pypi.python.org/pypi/pygraphviz/
# MinGW; if error - "Unable to find vcvarsall.bat"
# mingw-get-inst-20100831.exe, support mno-cygwin argument
# Remember to add MinGW\bin to System Variable - PATH
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20100831/

Python27\Lib\distutils\unixccompiler.py
# If "TypeError: ‘NoneType’ object is unsubscriptable", Change
compiler = os.path.basename(sysconfig.get_config_var("CC"))
# To
compiler = "gcc"
# Change it back later on

pygraphviz-1.1\setup.py
# Change
library_path=None
include_path=None
# To
library_path = r"C:\Graphviz2.30\bin"
include_path = r"C:\Graphviz2.30\include\graphviz"
# If the library_path didn't work, try library_path="C:/Graphviz2.30/lib/release/lib"

cmd
pygraphviz-1.1>python setup.py build -c mingw32
# Copy pygraphviz-1.1\build\lib.win32-2.7\pygraphviz into Python27\libs\site-packages\pygraphviz

Test
import pygraphviz as pg
G = pg.AGraph()
G.add_node(u"Main", shape="rect", style="rounded", fontsize=18)
G.add_node(u"A")
G.add_node(u"B")
G.add_node(u"C")
G.add_edge(u"A", u"Main")
G.add_edge(u"B", u"Main")
G.add_edge(u"C", u"Main")
G.draw('test.png', format='png', prog='neato')

No comments :

Post a Comment