Python 3.x support for pygraphviz

2,948 views
Skip to first unread message

Sybren A. Stüvel

unread,
Nov 5, 2012, 9:00:59 AM11/5/12
to pygraphvi...@googlegroups.com
Dear Group,

This is my first post to this group, so let me introduce myself. I'm Sybren Stüvel, PhD student at Utrecht University, The Netherlands, and I'm researching crowd animation at the Games & Virtual Worlds group. For our research we use animation software based on Ogre/C++ with Python 3.2 bindings. For our graphs we've used NetworkX + Matplotlib with great success. However, now I need multigraphs, which are not drawn correctly with Matplotlib. I was hoping to use the Graphviz interface for this, but alas, pygraphviz doesn't work on Python 3.

My question is: when will Python 3 be supported? Is there any way I can help to speed this up (short of porting it all myself)? As far as I can see all dependencies of PyGraphviz (like SWIG) support Py3, so that shouldn't pose a problem.

Kind regards,
Sybren

Aric Hagberg

unread,
Nov 5, 2012, 1:59:58 PM11/5/12
to pygraphvi...@googlegroups.com
The issue is the string handling in PyGraphviz. It was written in the
ancient era before Python3 split bytes and strings. I haven't looked
into how SWIG handles that but at any rate PyGraphviz has unicode
types at the core of the Python code (e.g the Node type is a subclass
of unicode). All of that would need to be changed.

I think it could be fixed to work correctly with the Python3 string
type but I didn't see an easy way to have one version that worked with
both Python2 and Python3. So I've got no plans to do that at this
point.

PyGraphviz grew toward the same interface/API as NetworkX but I don't
think that is the correct approach now. A better approach might be to
create a simpler wrapper to just the layout and drawing part
(PyGraphviz allows modifying the graph and more). If that was done
with Cython, which I like a lot, then maybe the Windows users would
finally be able to correctly build PyGraphviz too.

Aric

Philip Axer

unread,
Feb 23, 2013, 7:20:48 PM2/23/13
to pygraphvi...@googlegroups.com
I just finished a crude python3 port. At the moment the code only works under python3 (tested with 3.3). Expect it to be buggy.
You can find the source here:

Philip

BrianO

unread,
Feb 24, 2013, 8:32:50 AM2/24/13
to pygraphvi...@googlegroups.com
Thanks for undertaking this!
I installed pygraphviz-1.2-dev without incident --
 infrastructure is Python 3.3,  Xcode 4.6, Mac OS X 10.7.

Forewarned is forearmed - yes, some bugs.
Specifically, I couldn't get the *examples* to run. I've tried two:

attributes.py
       It seems the AGraph.string() method has a problem
simple.py
        AGraph.string trouble again, and then
        AGraph.layout method crashed python
       (more precisely, PyDev, under Eclipse), while trying to run neato

FYI.
Keep up the good work!

Philip Axer

unread,
Feb 24, 2013, 9:25:20 AM2/24/13
to pygraphvi...@googlegroups.com
I must admit that I didn't try (nor port) the supplied tests. I had my own little application that uses pygraphviz which I used to "test" things.
Long story short, please pull the recent changes and try again. I fixed the bugs you mentioned.

BrianO

unread,
Feb 24, 2013, 9:08:46 PM2/24/13
to pygraphvi...@googlegroups.com
Glad to hear it. I'll get latest and let you know how it goes - I'm optimistic

BrianO

unread,
Feb 24, 2013, 11:54:41 PM2/24/13
to pygraphvi...@googlegroups.com
All the examples work now :)
setup does *not* copy the data file for the miles.py example, but then, it probably never did.
I'll be using it more extensively and will relate any... issues.
Thanks again!

Roman Kutlak

unread,
Mar 12, 2013, 12:54:09 PM3/12/13
to pygraphvi...@googlegroups.com
Hi, great to see that pygraphviz is coming to Python3. I think I found a bug. When you call AGraph.layout("dot") and then AGraph.draw("file") my program terminates with segmentation fault, but calling AGraph.draw("file", prog="dot") seems to work. I guess the problem is in agraph.py in the function layout() (a mismatch between bytes and strings?).

Roman


Semyon Zharov

unread,
Mar 22, 2013, 8:41:38 AM3/22/13
to pygraphvi...@googlegroups.com
Hi!
I'm Windows user and need to use multidirgraph from networkx.
And i'n going to use graphviz to plot graph, because Matplotlib doesn't support selfloop and parallel edges.
How can I instal version of Philip Axer? 

I set 
library_path='C:\Program Files (x86)\Graphviz2.30\lib\release\lib'
include_path='C:\Program Files (x86)\Graphviz2.30\include\graphviz'
in setup.py.

But python setup.py build -c mingw32 is not correct( 
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-IC:\Program Files (x86)\Graphv
iz2.30\include\graphviz" -IC:\Python33\include -IC:\Python33\include -c pygraphv
iz/graphviz_wrap.c -o build\temp.win-amd64-3.3\Release\pygraphviz\graphviz_wrap.
o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:3347: warning: return makes integer from pointer with
out a cast
writing build\temp.win-amd64-3.3\Release\pygraphviz\_graphviz.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-3.3\Release\pyg
raphviz\graphviz_wrap.o build\temp.win-amd64-3.3\Release\pygraphviz\_graphviz.de
elease\lib" -LC:\Python33\libs -LC:\Python33\PCbuild\amd64 "-Wl,-RC:\Program Fil
elease\lib" -lcgraph -lcdt -lpython33 -lmsvcr100 -o build\lib.win-amd64-3.3\pygr
aphviz\_graphviz.pyd
c:/mingw/bin/../lib/gcc/mingw32/4.3.3/../../../../mingw32/bin/ld.exe: cannot fin
d -lcgraph
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

воскресенье, 24 февраля 2013 г., 18:25:20 UTC+4 пользователь Philip Axer написал:
Reply all
Reply to author
Forward
0 new messages