Error occurred when running the code of GCN from the tutorial


I am a beginner to pytorch and DGL, and can anybody give any comments about the problem?

The code is downloaded from the tutorial website:

Traceback (most recent call last):
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/”, line 922, in create_graph_index
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/”, line 660, in from_networkx
for e in nx_graph.edges:
TypeError: ‘method’ object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 116, in
g, features, labels, mask = load_cora_data()
File “”, line 108, in load_cora_data
g = DGLGraph(data.graph)
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/”, line 181, in init
self._graph = create_graph_index(graph_data, multigraph, readonly)
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/”, line 925, in create_graph_index
% type(graph_data))
dgl._ffi.base.DGLError: Error while creating graph from input of type “<class ‘networkx.classes.digraph.DiGraph’>”.



Which version of networkx are you using?

You can get the version by this:

import networkx


The version of NetworkX is 1.11

Python 3.5.3 |Anaconda custom (64-bit)| (default, Mar 6 2017, 11:58:13)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import networkx
>>> networkx.version


It seems your networkx version is too old.
Update it by using

conda update networkx


pip install --upgrade networkx

And after this, the new version is expected to be 2.2.


The problem is fixed after updating the networkX. Thanks very much.

However, another problem occurred in Can you also give any suggestions?


Hi, there seems to be many related problems and solutions on the internet like this. See if some of the solutions people propose can solve your issue.


It seems a python bug. Upgrade python may fix this.


Thank you very much. I will check it.


Thank for your help very much. There are no problems when I run the gcn in the directory “examples/pytorch” in the project. I will fix it later.