1

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

3
  • Check the installed version, the environment you are already working on, etc There is nothing else which we can help you. Commented Jun 3, 2019 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. Commented Jun 4, 2019 at 0: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 Commented Jun 4, 2019 at 9:47

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.