简体   繁体   中英

AttributeError: module 'networkx' has no attribute 'complete_graph'

In my code

import matplotlib.pyplot as plt
import networkx as nx

G = nx.complete_graph(6)
nx.draw(G)
plt.show()

I'm getting this error in spyder,

AttributeError: module 'networkx' has no attribute 'complete_graph'

networkx 2.2 is already installed so where is the problem

I tested your code and it works for me without problems, with networkx 2.2 installed via pip in Python 3.6.3 and tested with networkx development version too.

How you name the file in which you execute this code? Take care because if you name it networkx.py it won't work. This is the only possibility I can think of, because if I name networkx.py , it doesn't work and I get the same error than you; if I rename it, it works.

I searched in Stack Overflow and in Internet in general an I find many questions and answers about other attributes of networkx that doesn't work normally, but most of them of previous versions and no one related with complete_graph . Check this search , it might help you to find something.

Edit

Take a look at the section "Locating Modules" in the page about Python modules in Tutorials Point. The reason why you may be having this error is because the first place to search a module you import in your file is the same directory.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM