已安装 networkx 但无法导入

networkx installed but cannot import

我已经安装了 networkx,但是当我尝试将它导入 jupyter notebook 时,显示了一个错误

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-16-6743fca41c5c> in <module>
      1 import numpy as np
      2 import matplotlib.pyplot as plt
----> 3 import networkx as nx

ModuleNotFoundError: No module named 'networkx'

我已经卸载并重新安装了几次,但没有任何改变。

当我在终端中导入它时它起作用了。

(base) MacBook-Pro:~ gary$ python
Python 3.7.7 (default, Mar 26 2020, 10:32:53) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import networkx
>>> print(networkx.__version__)
2.5

谁能帮我解决这个问题?

你需要写一个感叹号。 ! pip install [package_name]

激活另一个环境并切换回来。这对我有用。