繁体   English   中英

Numpy 在使用 Spyder (WINDOWS) 的 Anaconda 环境中导入错误

[英]Numpy Import Error in Anaconda Environment using Spyder (WINDOWS)

背景

就在两天前,我能够运行任何具有 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 版本,它看起来也很好在此处输入图像描述

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

此处尝试的解决方案

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

导入 numpy c 扩展失败

在 Spyder 中导入 numpy package,Python

python Spyder 未导入 numpy

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

无法导入 numpy anaconda

导入错误:Anaconda numpy(numpy 和 Anaconda 已经安装,virtualenv)

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

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

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

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

pip install --upgrade pandas && pip install --upgrade numpy

这个命令也可以工作:

pip uninstall pandas && pip uninstall numpy && pip install pandas

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM