I wish to take a graph, G, created in networkx and convert it to an igraph, g, for use with the leidenalg community detection package. This used to work for me, but now I'm encountering problems.
Working with Python 3 in a Jupyter notebook on a Mac running Catalina OSX. Python-igraph is version 0.7.1.post7.
import numpy as np
import networkx as nx
import igraph as ig
A=np.matrix([[0,7,7,0,0],[7,0,6,0,0],[7,6,0,2,1],[0,0,2,0,4],[0,0,1,4,0]])
G=nx.from_numpy_matrix(A)
nx.write_graphml(G,'graph.graphml')
g = ig.read('graph.graphml',format="graphml")
The error message says "module 'igraph' has no attribute 'read'" Replacing the last line with
g=ig.Read_GraphML('graph.graphml')
does not eliminate the error message.
For some reason, this does work in Spyder with Python 3.7
My guess is that you have installed the wrong package in your virtualenv.
There are 2 libraries:
pip install igraph
) brew install igraph && pip install python-igraph
). This is the one which contains the read
method. Both can be referred to as import igraph
.
Try to run pip freeze
to check if in your environment you have installed the correct package.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.