【问题标题】:Numpy Import Error in Anaconda Environment using Spyder (WINDOWS)使用 Spyder (WINDOWS) 的 Anaconda 环境中的 Numpy 导入错误
【发布时间】:2021-04-20 18:08:15
【问题描述】:

背景

就在两天前,我能够运行任何具有 numpy 依赖项的程序。现在,当我尝试使用 pandas、matplotlib 或任何依赖于 numpy 的模块运行我的代码时,我收到以下错误:

Traceback (most recent call last):

  File "<ipython-input-8-8fcf286af663>", line 7, in <module>
    import numpy

  File "path\to\Python\Python38\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core

  File "path\to\Python\Python38\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)

ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "C:\ProgramData\Anaconda3\pythonw.exe"
  * The NumPy version is: "1.19.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

设置检查

返回消息引用了此站点:https://numpy.org/devdocs/user/troubleshooting-importerror.html,但没有任何帮助。

我检查了我的 Path 变量以确保所有必需的目录位置都在那里并且没有问题。

当我使用python -c "import numpy; print('done')"从cmd编译代码时成功导入numpy

我正在使用 anaconda 环境,即 Spyder IDE,而且两天前还好。

我从pythonw.exe检查了python版本,看起来也不错

我的环境可能有什么问题?

这里尝试的解决方案

另外,我检查了以下链接,但没有成功:

Importing the numpy c-extensions failed

importing numpy package in Spyder, Python

python Spyder not importing numpy

https://github.com/numpy/numpy/issues/15090

Can't import numpy anaconda

Import error: Anaconda numpy (numpy and Anaconda already installed, virtualenv)

【问题讨论】:

    标签: python python-3.x numpy anaconda spyder


    【解决方案1】:

    原来我的问题很简单。我尝试的主要解决方案是卸载并重新安装。

    每次我安装和卸载模块时,我都是从标准命令行执行的。

    这是错误,因为 anaconda 使用自己的虚拟环境来存储数据。

    所以我所要做的就是从 anaconda 命令提示符运行这个命令:

    pip install --upgrade pandas &amp;&amp; pip install --upgrade numpy

    这个命令也可以工作:

    pip uninstall pandas &amp;&amp; pip uninstall numpy &amp;&amp; pip install pandas

    (因为上次安装会自动下载 pandas 的所有依赖项,即 numpy

    【讨论】:

      猜你喜欢
      • 2019-05-09
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 2019-10-12
      • 1970-01-01
      • 2016-10-23
      相关资源
      最近更新 更多