7
from networkx import *
import matplotlib.pyplot as plt

I've imported the networkx library which previously (yesterday) allowed me to create a random graph. Running the same code again today I'm getting import errors. I am using this on Jupyter notebook/Anaconda Python.

AttributeError                            Traceback (most recent call last)
<ipython-input-13-d245e6f3c125> in <module>()
----> 1 from networkx import *
  2 import matplotlib.pyplot as plt

C:\Anaconda3\lib\site-packages\networkx\__init__.py in <module>()
 96 from networkx.tests.test import run as test
 97 
---> 98 import networkx.drawing
 99 from networkx.drawing import *

C:\Anaconda3\lib\site-packages\networkx\drawing\__init__.py in <module>()
  3 from .layout import *
  4 from .nx_pylab import *
----> 5 from . import nx_agraph
  6 from . import nx_pydot

C:\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in <module>()
272     return node_pos
273 
--> 274 @nx.utils.open_file(5, 'w')
275 def view_pygraphviz(G, edgelabel=None, prog='dot', args='',
276                        suffix='', path=None):

AttributeError: module 'networkx' has no attribute 'utils'
CodeMuch
  • 81
  • 1
  • 5
  • 1
    Has the version changed since when you used it before? – Aaron N. Brock Apr 10 '18 at 13:38
  • Hi @codemuch, please put the error in the text. That way your question will be useful to others even when the image is no longer there, and the error will also be searchable. Welcome to SO. –  Apr 10 '18 at 13:40
  • I can't find anything new on the networx library. The newest thing on there was a week ago, which suggests it shouldn't of worked yesterday. – CodeMuch Apr 10 '18 at 13:40
  • Have a look here: https://stackoverflow.com/questions/42084985/attributeerror-module-networkx-has-no-attribute-graph –  Apr 10 '18 at 13:41
  • what version of networkx and python do you have? – Joel Apr 10 '18 at 14:33
  • Usually, we import with `import networkx as nx`. Do you still have the same error with this import ? – michaelg Apr 12 '18 at 14:41

4 Answers4

5

I have the same quesion just now. It seems like it's because I use Ctrl+c while the py file is import the networkx. So I close the environment and restart again. Everything is normal then.

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
Shawn
  • 51
  • 1
2

I had to restart the kernel in my jupyter notebook and now it works.

0

This module is imported once. Usually the promblem in Jypyter Notebook

Try to reload your .ipy file (or notebooke)

0

I too had the same problem. Had named the file as networkx.py and ran the code to find that the same error pops up. Turned out I had to rename the file (networkx_1.py) and the error was no longer there. Hope it helps.

Jodhvir Singh
  • 345
  • 1
  • 3
  • 11