首页 > 解决方案 > AttributeError: module 'graph_tool.draw' has no attribute 'draw_hierarchy' 运行我的代码时返回,这是不正确的

问题描述

我正在尝试运行一个使用图形工具的脚本,并且代码返回:

/usr/lib/python3/dist-packages/graph_tool/all.py:40: RuntimeWarning: Error importing draw module, proceeding nevertheless: No module named 'cairo._cairo'
  warnings.warn(msg, RuntimeWarning)
Nuclear_Overhauser_effect
['the', 'nuclear', 'overhauser', 'effect', 'noe', 'is', 'the', 'transfer', 'of', 'nuclear']
Traceback (most recent call last):
  File "/home/qhama/Desktop/hSBM_Topicmodel/graphtools_tut.py", line 39, in <module>
    model.plot(filename='tmp.png', nedges=1000)
  File "/home/qhama/Desktop/hSBM_Topicmodel/sbmtm.py", line 183, in plot
    subsample_edges=nedges, hshortcuts=1, hide=0)
  File "/usr/lib/python3/dist-packages/graph_tool/inference/nested_blockmodel.py", line 934, in draw
    return graph_tool.draw.draw_hierarchy(self, **kwargs)
AttributeError: module 'graph_tool.draw' has no attribute 'draw_hierarchy' 

尝试重新安装 cairo 和每个依赖项

# Creating an instance of the sbtm-class

model = sbmtm()

# We have to create the word document network from the corpus
model.make_graph(texts, documents=titles)
gt.seed_rng(32)
model.fit()

# Plot the result
model.plot(filename='tmp.png', nedges=1000)
model.topics(l=1, n=20)

标签: pythongraph-tool

解决方案


在运行代码之前尝试导入所有 graph_tool 子模块,它可能会起作用。它对我有用。

import graph_tool.all as gt

推荐阅读