Installing PyGraphviz on Windows

Share

Django Extensions provides a bunch of management commands for the Django Framework. One of the most handy is the graph_models command. This command creates a visual representation of the Django models existing in the database.

In order to use this command you need to have Graphviz and PyGraphviz installed on your machine. Graphviz is a package of open-source tools for representing structural information as diagrams of abstract graphs and networks. PyGraphviz is a Python interface for Graphviz and allows you can create, edit, read, write, and draw Graphviz graphs.

Download and install Graphviz from this link: http://www.graphviz.org/Download_windows.php.

I couldn’t install PyGraphviz using easy_install, because it depends on Graphviz, and easy_install doesn’t know where to find Graphviz.

Download PyGraphviz(1.1) from this link: http://networkx.lanl.gov/download/pygraphviz/, and extract it.

Adjust “setup.py” file to reflect your Graphviz instalation.


library_path='C:/Program Files (x86)/Graphviz 2.28/lib/release/lib'
include_path='C:/Program Files (x86)/Graphviz 2.28/include/graphviz'

Normally, you would run python setup.py install to build and install a python application, but in this case we need to do some extra work. Running this command will output an error:


"Unable to find vcvarsall.bat"

To solve this issue, PyGraphviz needs to be compiled with a MSVC or mingw32 compiler. I haven’t found a Windows build for PyGraphviz so the only option was to built this myself.

I have used an older release of mingw because the current one doesn’t support the mno-cygwin argument anymore.

Download and install mingw-get-inst-20100831.exe from this link:
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/

Add mingw/bin directory to the system path.

Change line 285 from “c:\python27\lib\distutils\unixcompiler.py” from

1
compiler = os.path.basename(sysconfig.get_config_var("CC"))

to

1
compiler = "gcc".

or there will be an error “TypeError: ‘NoneType’ object is unsubscriptable”. Change it back after finishing installing PyGraphviz.

Now it’s time to build PyGraphviz:

C:\pygraphviz-1.1>python setup.py build -c mingw32
library_path=C:/Graphviz/lib/release/lib
include_path=C:/Graphviz/include/graphviz
running build
running build_py
creating build
creating build\lib.win32-2.7
creating build\lib.win32-2.7\pygraphviz
copying pygraphviz\agraph.py -> build\lib.win32-2.7\pygraphviz
copying pygraphviz\graphviz.py -> build\lib.win32-2.7\pygraphviz
copying pygraphviz\release.py -> build\lib.win32-2.7\pygraphviz
copying pygraphviz\version.py -> build\lib.win32-2.7\pygraphviz
copying pygraphviz\__init__.py -> build\lib.win32-2.7\pygraphviz
creating build\lib.win32-2.7\pygraphviz\tests
copying pygraphviz\tests\test.py -> build\lib.win32-2.7\pygraphviz\tests
copying pygraphviz\tests\__init__.py -> build\lib.win32-2.7\pygraphviz\tests
copying pygraphviz\tests\attributes.txt -> build\lib.win32-2.7\pygraphviz\tests
copying pygraphviz\tests\graph.txt -> build\lib.win32-2.7\pygraphviz\tests
copying pygraphviz\tests\layout_draw.txt -> build\lib.win32-2.7\pygraphviz\tests
copying pygraphviz\tests\unicode.txt -> build\lib.win32-2.7\pygraphviz\tests
running build_ext
building 'pygraphviz._graphviz' extension
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
creating build\temp.win32-2.7\Release\pygraphviz
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:/Graphviz/include/graphviz -
IC:\Python27\include -IC:\Python27\PC -c pygraphviz/graphviz_wrap.c -o build\tem
p.win32-2.7\Release\pygraphviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:2855:5: warning: return makes integer from pointer wi
thout a cast
writing build\temp.win32-2.7\Release\pygraphviz\_graphviz.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\pygraph
viz\graphviz_wrap.o build\temp.win32-2.7\Release\pygraphviz\_graphviz.def -LC:/G
raphviz/lib/release/lib -LC:\Python27\libs -LC:\Python27\PCbuild -Wl,-RC:/Graphv
iz/lib/release/lib -lcgraph -lcdt -lpython27 -lmsvcr90 -o build\lib.win32-2.7\py
graphviz\_graphviz.pyd

Copy the contents of the build/lib.win32-2.7 directory(single sub-folder called pygraphviz) into your Python’s site-packages folder.

You can create a PNG image file called my_project_visualized.png with application grouping running the following command:

manage.py graph_models -a -g -o my_project_visualized.png

Django Extensions
Graphviz website
PyGraphviz website
Minimalist GNU for Windows

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

8 thoughts on “Installing PyGraphviz on Windows”
  • sushant says:

    I did what you have said above but it gives error as:
    “error: command ‘gcc’ failed no such file or directory”

    January 21, 2012 at 4:53 am
  • Ioan Seicean says:

    You didn’t add mingw/bin directory to the system path.

    March 13, 2012 at 2:47 pm
  • NY says:

    Hi, I follow the steps you introduce, and in the last part, I don’t understand this sentence.
    “Copy the contents of the build/lib.win32-2.7 directory(single sub-folder called pygraphviz) into your Python’s site-packages folder.”

    1, do you mean copy “C:pygraphviz-1.1uildlib.win32-2.7pygraphviz” this directory?
    2, what is Python’s site-packages folder?

    April 19, 2012 at 4:18 am
  • NY says:

    After following the steps you gave, I got the the install massage you paste there. Besides, it still gives error as:
    “c:/mingw/bin../lib/gcc/mingw32/4.5.0/../../../mingw32/bin/ld.exe: cannot find -lcgraph
    c:/mingw/bin../lib/gcc/mingw32/4.5.0/../../../mingw32/bin/ld.exe: cannot find -lcdt
    collect2: ld returned 1 exit status
    error: command ‘gcc’ failed with exit status 1”

    April 19, 2012 at 4:25 am
  • NY says:

    Sorry to trouble again, I know what the last sentence mean now, but I still have the error message, do you know how to deal with it?

    April 19, 2012 at 4:31 am
  • NY says:

    Hi, there, my problem have been solved, I just want to add if others still have the same problem here.

    If change the library path to
    library_path=’C:\Graphviz 2.28\lib\debug\lib’
    my install process would work successfully.

    April 19, 2012 at 7:54 am
    • Ioan Seicean says:

      I have installed PyGraphviz twice. First time I had the library_path similar to yours. After several months, when I had to do the steps again I didn’t remember which installer/build versions to use. So the second time I have stored this information in the article hoping that will be helpful for other people that run into the same issue.

      April 25, 2012 at 9:55 am
  • fei says:

    according to your method,but i failed to install pygraphviz.next setp,I am stuped,so what i can’t know do?
    I add mingw/bin directory to the system path and also apply to compiler = “gcc”, it gives error as:“error: command ‘gcc’ failed no such file or directory”.

    June 4, 2012 at 3:17 pm

Comments are closed.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close