ModuleNotFoundError:Python 3.9 中没有名为“scipy”的模块

Woj*_*Woj 5 python scipy

我在 ubuntu 18.04 上运行 python3.9。我已经继续执行命令sudo apt-get install python-scipy并收到消息:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-scipy is already the newest version (0.19.1-2ubuntu1).
The following packages were automatically installed and are no longer required:
  linux-hwe-5.4-headers-5.4.0-42 linux-hwe-5.4-headers-5.4.0-53
  linux-hwe-5.4-headers-5.4.0-56 linux-hwe-5.4-headers-5.4.0-58
  linux-hwe-5.4-headers-5.4.0-59 linux-hwe-5.4-headers-5.4.0-60
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Run Code Online (Sandbox Code Playgroud)

然而,当我尝试运行使用的 python3.9 代码时from scipy import integrate,我收到错误:

ModuleNotFoundError: No module named 'scipy'
Run Code Online (Sandbox Code Playgroud)

我已经阅读了这篇文章并尝试使用卸载和安装 scipy

sudo apt-get install python3-scipy
Run Code Online (Sandbox Code Playgroud)

但这没有用。有什么建议么?

编辑 1:我尝试sudo pip3 install scipy生成了以下消息:

The directory '/home/nick/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nick/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Run Code Online (Sandbox Code Playgroud)

然而,当我尝试再次运行代码时,我仍然得到相同的结果ImportError

小智 6

也许尝试一下

python3.9 -m pip install scipy --user
Run Code Online (Sandbox Code Playgroud)

这将使用python3.9的pip将包安装到没有sudo权限的地方