Error when creating a graph from a NetworkX graph

when I study Chapter 1.4 about DGL in website: https://docs.dgl.ai/guide/graph-external.html
the code is:
import dgl
import torch as th
import scipy.sparse as sp
spmat = sp.rand(100, 100, density=0.05) # 5% nonzero entries
dgl.from_scipy(spmat) # from SciPy
import networkx as nx
nx_g = nx.path_graph(5) # a chain 0-1-2-3-4
dgl.from_networkx(nx_g) # from networkx

Error information:
Traceback (most recent call last):
File “D:/PycharmProject_data/DGL_env_test/test.py”, line 11, in
g = dgl.from_networkx(nx_g)
File “D:\Anaconda3\envs\DGL_python36\lib\site-packages\dgl\convert.py”, line 986, in from_networkx
nx_graph, idtype, edge_id_attr_name=edge_id_attr_name)
File “D:\Anaconda3\envs\DGL_python36\lib\site-packages\dgl\utils\data.py”, line 182, in graphdata2tensors
data, idtype, edge_id_attr_name=edge_id_attr_name)
File “D:\Anaconda3\envs\DGL_python36\lib\site-packages\dgl\utils\data.py”, line 92, in networkx2tensor
for e in nx_graph.edges:
TypeError: ‘method’ object is not iterable

Process finished with exit code 1

any answer is appreciate,Thanks!

What’s the DGL and NetworkX version?

Thank you for reply!
networkx version is 2.5
dgl version is 0.5.3

The code snippet works fine in my setting with DGL 0.5.3 and NetworkX 0.2.5. From the error message, I guess you by accident passed a DGLGraph to dgl.from_networkx. Can you try again?

Thank you for your reply!
The problem has been solved. I uninstalled the networkx 2.5, then found that there still existed networkx 1.11 therefore, I uninstall the networkx 1.11 and install networkx 2.5
The code works fine after above work.
Thank you !