Even if networkx is installed, it still throws a ModuleNotFoundError: No module named 'networkx'

Viewed 3974

I successfully installed networkx using pip install networkx. I also tested it with Python using command prompt, and it worked.

Picture of running the 'pip install networkx' command and testing it afterwards with cmd

Now, when I tried importing the module in Python IDLE, it throws the following error:

    Traceback (most recent call last):
  File "C:/Users/hp/Desktop/PROJECTS/osmnx/test.py", line 1, in <module>
    import networkx
ModuleNotFoundError: No module named 'networkx'

Here's a picture that shows that I did the import statement correctly and the error.

2 Answers

I solved the problem by upgrading my Python from 3.7.3 to 3.8.5. I ran the import statement after that, but it showed the same error. With that, what I did is to run the pip install networkx again in the Command Prompt, and it finally worked!

If your script are running using conda environment you can use: conda install networkx -y

So this will install networkx using conda package manager. It helped for my case: import networkx started working.

Related