Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

Installing PyGraphviz on Windows

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

Tags: django extension how to Python Windows

 Posted in: Java
November 28, 2011 | Ioan Seicean | 8 Comments

8 Responses

  • sushant
    January 21, 2012
    1

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

  • Ioan Seicean
    March 13, 2012
    2

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

  • NY
    April 19, 2012
    3

    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?

  • NY
    April 19, 2012
    4

    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″

  • NY
    April 19, 2012
    5

    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?

  • NY
    April 19, 2012
    6

    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.

  • Ioan Seicean
    April 25, 2012
    7

    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.

  • fei
    June 4, 2012
    8

    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”.


  • « Previous post
  • Next post »
  • Recent Posts

    • How to put online the Apache 2.4 Server
    • Exit from an Android application
    • Showing keyboard automatically in Android dialogs
    • Request Elevated Privileges in Windows Vista and 7 where UAC is enabled
    • Checkboxes unchecked value
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Laurent on GWT 2.1 – Uploading a file using the RPC mechanism
    • ketone review on GWT/GXT – File Upload
    • Seris on Multiple select ComboBox in RadGrid filter
    • Mihai Ionescu on Basic file encryption with PHP mcrypt using cryptastic class
    • Furqon on Basic file encryption with PHP mcrypt using cryptastic class
  • Archives

    • September 2012 (1)
    • August 2012 (2)
    • June 2012 (1)
    • March 2012 (1)
    • February 2012 (1)
    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (16)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (86)
      • Microsoft.NET (23)
      • Java (43)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (4)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (2)
    • Web Development (30)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (6)
      • Javascrip/AJAX (8)
      • PHP (8)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2013 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo