簡體   English   中英

AttributeError: module 'graph_tool.draw' has no attribute 'draw_hierarchy' 運行我的代碼時返回,這是不正確的

[英]AttributeError: module 'graph_tool.draw' has no attribute 'draw_hierarchy' is returned when running my code, which is not true

我正在嘗試運行一個使用圖形工具的腳本,代碼返回:

/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)

如果您仍在尋找,請參閱圖形工具需要哪些安裝依賴項/選項以包含 draw_hierarchy? 似乎談到了你的問題。 外賣是,您使用的版本可能是在編譯時缺少依賴項。 即除了重新安裝所有這些依賴項之外,您可能還需要在之后重新編譯。

該鏈接指出此問題與 GTK+ 依賴性問題有關,但我一直在運行除 cairo 之外的所有內容,但仍然遇到問題,因此可能是缺少其中任何一個都可能導致此問題。 要查看重新安裝后是否仍然遇到 cairo 問題(就像我一樣),請嘗試在任何 python 實例中import cairo並查看是否出現錯誤。

我目前的工作理論是默認的 cairo 包在 python 3.7 上有問題,需要重新編譯,這就是為什么單獨重新安裝是不夠的。 還沒有解決這個問題,但是通過上面的內容,您至少可以檢查一下這是否也是您遇到的問題,如果是,可以嘗試使用不同的 python 版本。

在運行代碼之前嘗試導入所有 graph_tool 子模塊,它可能會起作用。 它對我有用。

import graph_tool.all as gt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM