即使安装了networkx,它仍然会引发ModuleNotFoundError:没有名为“ networkx”的模块

问题描述

我已成功使用networkx安装了pip install networkx。我还使用命令提示符在Python上对其进行了测试,并且可以正常工作。

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

现在,当我尝试以Python IDLE导入模块时,它将引发以下错误

    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.

解决方法

我通过将Python从3.7.3升级到3.8.5解决了该问题。之后,我运行了import语句,但显示了相同的错误。这样,我所做的就是再次在命令提示符中运行pip install networkx,终于成功了!