【问题标题】:ModuleNotFoundError: No module named 'scipy' in python 3.9ModuleNotFoundError:python 3.9 中没有名为“scipy”的模块
【发布时间】:2021-05-06 22:52:25
【问题描述】:

我在 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.

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

ModuleNotFoundError: No module named 'scipy'

我已经阅读了这个 post 并尝试使用卸载和安装 scipy

sudo apt-get install python3-scipy

但这不起作用。有什么建议吗?

编辑 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.

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

【问题讨论】:

  • 尝试在pip3前加-H
  • Requirement already satisfied: scipy in /usr/lib/python3/dist-packages
  • 运行以下命令:pip freeze | grep scipy。它返回什么?

标签: python scipy


【解决方案1】:

使用 pipwin

pip install pipwin

下载后

pipwin install scipy

【讨论】:

  • 虽然此代码可能会为问题提供解决方案,但最好添加有关其工作原理/方式的上下文。这可以帮助未来的用户学习并将这些知识应用到他们自己的代码中。解释代码时,您也可能会得到用户的积极反馈/赞成。
【解决方案2】:

试试 pip3 install scipy, 如果返回一个ERRNO 13: access denied,那么试试pip3 install scipy --user

【讨论】:

    【解决方案3】:

    不妨试试

    python3.9 -m pip install scipy --user
    

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

    【讨论】:

    • 这是正确答案。两者都用于使用 python -mpip, 用户安装(如果不使用虚拟环境)。
    • Requirement already satisfied: scipy in /usr/local/lib/python3.9/site-packages (1.7.3) Requirement already satisfied: numpy<1.23.0,>=1.16.5 in /usr/local/lib/python3.9/site-packages (from scipy) (1.21.4) 但仍然得到这个:ModuleNotFoundError: No module named 'scipy'
    • 嗨@Dr.jacky,您的问题很可能是pippython 之间的不匹配。如果我是你,我会检查当前的python 是否确实是安装在/usr/local/bin 中的python3.9。有时系统中可能有多个python3.9,这使得事情很难处理......
    猜你喜欢
    • 2021-11-06
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-21
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多