lbe*_*gni 5 python graphviz segmentation-fault
我正在建立一个有大约3000个节点的图形。我编写了一个简单的python程序来实现graphviz的技巧,但是它给我带来了分割错误,而且我不知道为什么,如果图形太大或我是否我错过了一些东西。
代码是:
#!/usr/bin/env python
# Import graphviz
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz')
import gv
# Import pygraph
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph
from pygraph.algorithms.searching import breadth_first_search
from pygraph.readwrite.dot import write
# Graph creation
gr = graph()
file = open('nodes.dat', 'r')
line = file.readline()
while line:
gr.add_nodes([line[0:-1]])
line = file.readline()
file.close()
print 'nodes finished, beginning edges'
edges = open('edges_ok.dat', 'r')
edge = edges.readline()
while edge:
gr.add_edge((edge.split()[0], edge.split()[1]))
edge = edges.readline()
edges.close()
print 'edges finished'
print 'Drawing'
# Draw as PNG
dot = write(gr)
gvv = gv.readstring(dot)
gv.layout(gvv,'dot')
gv.render(gvv,'svg','graph.svg')
Run Code Online (Sandbox Code Playgroud)
并在gv.layout()通话时崩溃。
这些文件有点像:节点:
node1
node2
node3
Run Code Online (Sandbox Code Playgroud)
edges_ok:
node1 node2
node2 node3
Run Code Online (Sandbox Code Playgroud)