Search code examples
pythongraphvizdotpygraphvizpydot

Can't generate graph using graphviz and dot layout


I am using pygraphviz 1.6 to generate the a plot using Python 3.6. Unfortunately, I can't update Python. While generating the graph, the command graph.layout("dot") generates the error:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-d73a7e09eb44>", line 6, in <module>
    graph.layout("dot")
  File "/usr/local/lib/python3.6/dist-packages/pygraphviz/agraph.py", line 1422, in layout
    data = self._run_prog(prog, " ".join([args, "-T", fmt]))
  File "/usr/local/lib/python3.6/dist-packages/pygraphviz/agraph.py", line 1387, in _run_prog
    raise OSError(b"".join(errors).decode(self.encoding))
OSError: libpath/shortest.c:324: triangulation failed
libpath/shortest.c:200: destination point not in any triangle
Error: in routesplines, Pshortestpath failed

In order to reproduce the issue, you must download the file graph_data.txt from https://drive.google.com/file/d/12YjB752SfCrzHmycRDeYAH2PHL6gMiIJ/view?usp=sharing , and run the following code:

import pygraphviz as pgv
with open("graph_data.txt", "wb") as fp:
    graph_data = fp.read()
graph = pgv.AGraph()
graph.from_string(graph_data)
graph.layout("dot") 
graph.draw(settings.PIPELINE_GRAPH_PATH, format="pdf")

Solution

  • Following @sroush I uninstalled graphviz and reinstalled it building from scratch. The following is the code to do that:

    apt purge graphviz && \
      pip uninstall graphviz && \
        apt install -y libgts-dev && \
        pkg-config --libs gts && \
        pkg-config --cflags gts && \
        wget https://gitlab.com/api/v4/projects/4207231/packages/generic/graphviz-releases/5.0.0/graphviz-5.0.0.tar.gz && \
        tar -xvf graphviz-5.0.0.tar.gz && \
        cd graphviz-5.0.0/ && \
        ./configure --with-gts && \
        make && \
        make install
    

    Note that you may need to run some of the above commands with sudo as done here: https://github.com/ellson/MOTHBALLED-graphviz/issues/1237#issue-226453389