Nande
Nande

Reputation: 1

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

I'm trying to run a script that uses graph tools, and the code returns:

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

Tried reinstalling cairo and every dependency

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

Upvotes: 0

Views: 2558

Answers (2)

Bernardo Modenesi
Bernardo Modenesi

Reputation: 31

Try importing all graph_tool submodules before running your code and it might work. It worked for me.

import graph_tool.all as gt

Upvotes: 2

T. Shaffner
T. Shaffner

Reputation: 419

If you're still looking, the answer at What installation dependencies/options are needed for graph-tool to include draw_hierarchy? seems to speak to your issue. The takeaway being, the version you're using was likely compiled with missing dependencies. i.e. in addition to reinstalling all those dependencies you might need to recompile after.

That link notes this problem occurring with GTK+ dependency issues, but I've been running with everything except cairo and still hit the issue so it it may be that either of those missing may cause this. To see if you're still having cairo issues after reinstall (as I am) try to import cairo in any python instance and see if you get errors.

My current working theory is that the default cairo package has issues with python 3.7 and needs to be recompiled, which is why reinstalling alone isn't sufficient. Haven't solved that yet, but with the above you can at least check and see if this is a problem you're having too, and if so maybe try with a different python version.

Upvotes: 1

Related Questions