我正在尝试运行一个使用图形工具的脚本,代码返回:
/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)发布于 2019-06-04 22:34:10
如果你还在寻找,What installation dependencies/options are needed for graph-tool to include draw_hierarchy?上的答案似乎可以解决你的问题。需要注意的是,您使用的版本很可能是在编译时遗漏了依赖项。例如,除了重新安装所有这些依赖项之外,您可能还需要在之后重新编译这些依赖项。
该链接指出了与GTK+依赖问题有关的这个问题,但我已经运行了除cairo之外的所有程序,仍然遇到了这个问题,所以可能是缺少这两个程序中的任何一个都可能导致这个问题。要查看重新安装后是否仍然存在cairo问题(就像我一样),请尝试在任何python实例中使用import cairo命令,看看是否出现错误。
我目前的工作理论是,默认的cairo包在python3.7中存在问题,需要重新编译,这就是为什么仅重新安装是不够的。我还没有解决这个问题,但是使用上面的代码,你至少可以检查一下这是不是你也遇到的问题,如果是的话,也许可以尝试一下不同的python版本。
发布于 2020-11-27 22:47:57
在运行代码之前尝试导入所有graph_tool子模块,它可能会起作用。这对我很管用。
import graph_tool.all as gthttps://stackoverflow.com/questions/55443028
复制相似问题