Ask Your Question

How to make pygraphviz and sage compatible?

asked 2015-11-25 20:42:50 -0500

Bern gravatar image


I would like sage to help me when I am working with (un)directed graphs and quivers, and so on. After having played around with various possibilities, I would like to convert some stuff into a string and then let sage print something like a .ps - file that contains an image from dot (or something similar to this).

Unfortunately, I came across the following issue(s) and have no idea what to do now. With the sage version I installed, there is python 2.x as a delivered package. But it seems that sage complains about python3, what doesn't make sense to me.

Could you help me understand and solve the following:

boehmler@boehmler-X55A:~/Schreibtisch/bb/sage-6.9-x86_64-Linux$ ./sage ┌────────────────────────────────────────────────────────────────────┐ │ SageMath Version 6.9, Release Date: 2015-10-10 │ │ Type "notebook()" for the browser-based notebook interface. │ │ Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘

sage: import networkx as nx

sage: import matplotlib.pyplot as plt

sage: import matplotlib.image as mpimg

sage: from cStringIO import StringIO

sage: g = nx.dodecahedral_graph()

sage: d = nx.to_pydot(g)

AttributeError Traceback (most recent call last)

<ipython-input-6-0d33c400a5cf> in <module>()

----> 1 d = nx.to_pydot(g)

AttributeError: 'module' object has no attribute 'to_pydot'

sage: d = nx.to_agraph(g)

ImportError Traceback (most recent call last)

<ipython-input-7-d9254026fb59> in <module>()

----> 1 d = nx.to_agraph(g)

/home/boehmler/Schreibtisch/bb/sage-6.9-x86_64-Linux/local/lib/python/networkx/drawing/nx_agraph.pyc in


132         raise ImportError('requires pygraphviz ',

133                           ' ',

--> 134 '(not available for Python3)')

135     directed=N.is_directed()

136     strict=N.number_of_selfloops()==0 and not N.is_multigraph()

ImportError: ('requires pygraphviz ', ' ', '(not available for Python3)')

sage: Exiting Sage (CPU time 0m3.33s, Wall time 56m28.80s).

After typing boehmler@boehmler-X55A:~/Schreibtisch/bb/sage-6.9-x86_64-Linux$ sudo -H pip install pygraphviz

I get the message

Wall -Wstrict-prototypes -fPIC -I/usr/include/graphviz -I/usr/include/python2.7 -c pygraphviz/graphviz_wrap.c -o build/temp.linux-x86_64-2.7/pygraphviz/graphviz_wrap.o pygraphviz/graphviz_wrap.c:130:21: fatal error: Python.h: Datei oder Verzeichnis nicht gefunden # include <python.h> ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1


Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-6yZh3l/pygraphviz/';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-a6o8Fg-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-6yZh3l/pygraphviz

in the end. I would be grateful for any hints how to solve / fix this.

Thanks for the help!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-11-26 05:28:51 -0500

tmonteil gravatar image

updated 2015-11-26 05:35:01 -0500

When you write sudo -H pip install pygraphviz you try to install pygraphviz on your system, not within Sage vitrual environment.

To install pygraphviz on your Sage installation, you should:

  • install the graphviz-dev package in your system
  • run the command sage -pip install pygraphviz
edit flag offensive delete link more


Thank you very much for your answer.

Bern gravatar imageBern ( 2015-11-27 06:49:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-11-25 20:42:50 -0500

Seen: 2,766 times

Last updated: Nov 26 '15