graph_tool osx中缺少graph_draw?

时间:2015-01-27 19:46:07

标签: python macos graph-tool

我正在尝试使用graph_tool中的方法graph_draw。我在site_packages和文档

中看到对它的引用
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:   graph_draw
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:__all__ = ["graph_draw", "graphviz_draw", "fruchterman_reingold_layout",
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:    >>> gt.graph_draw(g, pos=pos, output="graph-draw-fr.pdf")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:       gt.graph_draw(g, pos=pos, output="graph-draw-fr.png")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:    >>> gt.graph_draw(g, pos=pos, output="graph-draw-arf.pdf")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:       gt.graph_draw(g, pos=pos, output="graph-draw-arf.png")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:            graph_draw(u, mivs, vertex_fillcolor=mivs)
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:    >>> gt.graph_draw(g, pos=pos, output="graph-draw-sfdp.pdf")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:       gt.graph_draw(g, pos=pos, output="graph-draw-sfdp.png")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:       http://www.mathematica-journal.com/issue/v10i1/graph_draw.html
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:            #graph_draw(u, pos)

但是当我尝试访问它时,它不存在......

>>> x=graph_tool.draw.GraphView
>>> x=graph_tool.draw.graph_draw()
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd_exec.py", line 3, in Exec
    exec exp in global_vars, local_vars
  File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'graph_draw'

我错过了什么吗?我应该如何访问这个?

谢谢!

2 个答案:

答案 0 :(得分:2)

这似乎是一个进口问题...... &#34; graph_draw&#34;函数从&#34; graph_tool.all&#34;导入。而不是来自&#34; graph_tool&#34;

我实际上在OSX 10.10.4上工作,当我导入&#34; graph_tool&#34;像这样的模块:

from graph_tool.all import *  

#create your graph object
g = Graph()

#add vertex 
vertex_1 = g.add_vertex() #here you create a vertex
vertex_2 = g.add_vertex() #here you create a vertex

#add edge
g.add_edge(vertex_1,vertex_2) #add an edge 

#draw you graph 
graph_draw(
    g,
    output="test.png"
)   

它的作品!

如果我按照&#34;导入示例&#34;您提供的还可以尝试:

from graph_tool.all import graph_draw,Graph  

#create your graph object
g = Graph()

#add a vertex at least
g.add_vertex()

#draw you graph 
graph_draw(
    g,
    output_size=(200,200),
    output="test.png"
)   

请尝试在您的计算机上运行上述代码之一,以便再次检查它是否是模块的导入问题或依赖项/安装问题

祝你好运

答案 1 :(得分:1)

确保安装了所有可选的依赖项:pycairo,matplotlib和gtk3(以及librsvg,如果您使用的是macports)。