networkx DiGraph Attribute Error self._succ

I believe your problem is similar to that in AttributeError: ‘DiGraph’ object has no attribute ‘_node’

The issue there is that the graph being investigated was created in networkx 1.x and then pickled. The graph then has the attributes that a networkx 1.x object has. I believe this happened for you as well.

You’ve now opened it and you’re applying tools from networkx 2.x to that graph. But those tools assume that it’s a networkx 2.x DiGraph, with all the attributes expected in a 2.x DiGraph. In particular it expects _succ to be defined for a node, which a 1.x DiGraph does not have.

So here are two approaches that I believe will work:

Short term solution
Remove networkx 2.x and replace with networkx 1.11.

This is not optimal because networkx 2.x is more powerful. Also code that has been written to work in both 2.x and 1.x (following the migration guide you mentioned) will be less efficient in 1.x (for example there will be places where the 1.x code is using lists and the 2.x code is using generators).

Long term solution
Convert the 1.x graph into a 2.x graph (I can’t test easily as I don’t have 1.x on my computer at the moment – If anyone tries this, please leave a comment saying whether this works and whether your network was weighted):

#you need commands here to load the 1.x graph G
#
import networkx as nx   #networkx 2.0
H = nx.DiGraph() #if it's a DiGraph()
#H=nx.Graph() #if it's a typical networkx Graph().

H.add_nodes_from(G.nodes(data=True))
H.add_edges_from(G.edges(data=True))

The data=True is used to make sure that any edge/node weights are preserved. H is now a networkx 2.x DiGraph, with the edges and nodes having whatever attributes G had. The networkx 2.x commands should work on it.

Bonus longer term solution
Contact the other researcher and warn him/her that the code example is now out of date.

Leave a Comment