0

I know it is a duplicate, but this hasn't solved my issue nor other guide online has.
I have installed the Anaconda distribution and it is the only Python environment I have on this computer. I always used Jupyter as Python "engine" and things worked flawlessly up until now, where I have switched to Sublime editor + CMD. I have tried to reinstall it via pip install -U networkx and via downloading from Git and then pip install . but none of them worked.

import networkx as nx

gr= nx.Graph()



Traceback (most recent call last):
  File "networkx.py", line 1, in <module>
    import networkx as nx
  File "C:\Users\Utente\nx\networkx.py", line 3, in <module>
    gr = nx.Graph()
AttributeError: module 'networkx' has no attribute 'Graph'

For whatever reason, using Jupyter QtConsole works, but I cannot use that to write and debug code

davide m.
  • 452
  • 4
  • 19
  • Check the installed version, the environment you are already working on, etc There is nothing else which we can help you. – OSainz Jun 03 '19 at 19:59
  • This should work. So it seems like something is wrong with the installation. Try `nx.__version__` to check what version of networkx you have. – Joel Jun 04 '19 at 00:52
  • the version is the latest 2.3, though `nx.__version__` doesn't work, again the same `AttributeError`. the environment variable is set to be the directory of Anaconda, every other Python command and library works just fine, this doesn't – davide m. Jun 04 '19 at 09:47

2 Answers2

5

The problem is probably the name of your python file. From your error message I see, your file is named networkx.py. Rename that to something different like networks.py will probably resolve your problem.

Background

The import try to import your file and not the package. Since your file does not implement Graph or __version__ an error is raised.

Sparky05
  • 4,692
  • 1
  • 10
  • 27
0

I was also facing this kind of issue. So, first, try to save your file as another name except for network and then run the program again and don't forget to delete the old file if it was named as network.py if you are using the same directory.