Python 导入错误:无法导入名称 NUMPY_MKL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37267399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:09:17  来源:igfitidea点击:

ImportError: cannot import name NUMPY_MKL

pythonwindowspython-2.7numpyscipy

提问by Steve

I am trying to run the following simple code

我正在尝试运行以下简单代码

import scipy
scipy.test()

But I am getting the following error

但我收到以下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 586, in runfile
    execfile(filename, namespace)
  File "C:/Users/Mustafa/Documents/My Python Code/SpectralGraphAnalysis/main.py", line 8, in <module>
    import scipy
  File "C:\Python27\lib\site-packages\scipy\__init__.py", line 61, in <module>
    from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl
ImportError: cannot import name NUMPY_MKL

I am using python 2.7 under windows 10.

我在 Windows 10 下使用 python 2.7。

I have installed scipybut that does not seem to solve the problem

我已经安装,scipy但似乎并没有解决问题

Any help is appreciated.

任何帮助表示赞赏。

回答by VMAtm

If you look at the line which is causing the error, you'll see this:

如果您查看导致错误的行,您会看到:

from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl

This line comment states the dependency as numpy+mkl(numpywith Intel Math Kernel Library). This means that you've installed the numpyby pip, but the scipywas installed by precompiled archive, which expects numpy+mkl.

此行注释将依赖项声明为numpy+mkl( numpywith Intel Math Kernel Library)。这意味着您已经安装了numpyby pip,但scipy是由预编译存档安装的,它需要numpy+mkl.

This problem can be easy solved by installation for numpy+mklfrom whl file from here.

这个问题可以通过numpy+mkl这里安装whl 文件来轻松解决。

回答by Andrew

Reinstall numpy-1.11.0_XXX.whl (for your Python) from www.lfd.uci.edu/~gohlke/pythonlibs. This file has the same name and version if compare with the variant downloaded by me earlier 29.03.2016, but its size and content differ from old variant. After re-installation error disappeared.

www.lfd.uci.edu/~gohlke/pythonlibs重新安装 numpy-1.11.0_XXX.whl(用于您的 Python)。如果与我在 29.03.2016 之前下载的变体相比,该文件具有相同的名称和版本,但其大小和内容与旧变体不同。重新安装后错误消失。

Second option - return back to scipy 0.17.0 from 0.17.1

第二个选项 - 从 0.17.1 回到 scipy 0.17.0

P.S. I use Windows 64-bit version of Python 3.5.1, so can't guarantee that numpy for Python 2.7 is already corrected.

PS 我使用的是 Windows 64 位版本的 Python 3.5.1,所以不能保证 Python 2.7 的 numpy 已经得到纠正。

回答by Lenny

I'm not sure if this is a good solution but it removed the error. I commented out the line:

我不确定这是否是一个好的解决方案,但它消除了错误。我注释掉了这一行:

from numpy._distributor_init import NUMPY_MKL 

and it worked. Not sure if this will cause other features to break though

它奏效了。不确定这是否会导致其他功能中断

回答by user3046442

I had the same problem while installing gensim on windows. Gensim is dependent on scipy and scipy on numpy. Making all three work is real pain. It took me a lot of time to make all there work on same time.

我在 Windows 上安装 gensim 时遇到了同样的问题。Gensim 依赖于 scipy,而 scipy 依赖于 numpy。让这三者都工作是真正的痛苦。我花了很多时间才能让所有这些都在同一时间工作。

Solution: If you are using windows make sure you install numpy+mkl instead of just numpy. If you have already installed scipy and numpy, uninstall then using "pip uninstall scipy" and "pip uninstall numpy"

解决方案:如果您使用的是 Windows,请确保安装 numpy+mkl 而不仅仅是 numpy。如果您已经安装了 scipy 和 numpy,请使用“pip uninstall scipy”和“pip uninstall numpy”卸载

Then download numpy-1.13.1+mkl-cp34-cp34m-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpyand install using pip install numpy-1.13.1+mkl-cp34-cp34m-win32.wh Note: in cp34-cp34m 34 represent the version of python you are using, so download the relevant version.

然后从http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy下载 numpy-1.13.1+mkl-cp34-cp34m-win32.whl 并使用 pip install numpy-1.13.1+mkl- 安装cp34-cp34m-win32.wh 注:cp34-cp34m中的34代表你使用的python版本,下载相关版本即可。

Now download scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy(appropriate version for your python and system) and install using "pip install scipy?0.19.1?cp34?cp34m?win32.whl"

现在从http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy(适用于您的 python 和系统的版本)下载 scipy并使用“pip install scipy?0.19.1?cp34?cp34m?win32”进行安装。什么"

Your numpy and Scipy both should work now. These binaries by Christoph Gohlke makes it very easy to install python packages on windows. But make sure you download all the dependent packages from there.

你的 numpy 和 Scipy 现在都应该可以工作了。Christoph Gohlke 的这些二进制文件使得在 Windows 上安装 python 包变得非常容易。但请确保从那里下载所有依赖包。

回答by Adrian

I don't have enough reputation to comment but I want to add, that the cp number of the .whl file stands for your python version.

我没有足够的声誉来发表评论,但我想补充一点,.whl 文件的 cp 编号代表您的 python 版本。

cp35 -> Python 3.5.x

cp35 -> Python 3.5.x

cp36 -> Python 3.6.x

cp36 -> Python 3.6.x

cp37 -> Python 3.7.x

cp37 -> Python 3.7.x

I think it's pretty obvious but still I wasted almost an hour because of this and maybe other people struggle with that, too.

我认为这很明显,但我仍然因此浪费了将近一个小时,也许其他人也为此而苦苦挣扎。

So for me worked version cp36 that I downloaded here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpysince I am using Python 3.6.8.

所以对我来说,我在这里下载了 cp36 版本:https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy, 因为我使用的是 Python 3.6.8。

Then I uninstalled numpy:

然后我卸载了numpy:

pip uninstall numpy 

Then I installed numpy+mkl:

然后我安装了numpy+mkl:

pip install <destination of your .whl file>

回答by Simbarashe Mupfururirwa

The reason for the error is you upgraded your numpy library of which there are some functionalities from scipy that are required by the current version for it to run which may not be found in scipy. Just upgrade your scipy library using python -m pip install scipy --upgrade. I was facing the same error and this solution worked on my python 3.5.

错误的原因是您升级了 numpy 库,其中有一些来自 scipy 的功能,这些功能是当前版本运行所需的,而在 scipy 中可能找不到。只需使用 python -m pip install scipy --upgrade 升级您的 scipy 库。我遇到了同样的错误,这个解决方案适用于我的 python 3.5。

回答by feng ling

yes,Just reinstall numpy,it works.

是的,只需重新安装numpy,它就可以工作。

回答by manoj prashant k

From your log its clear that numpypackage is missing. As mention in the PyPI package:

从您的日志中可以清楚地看出numpy软件包丢失。正如PyPI 包中提到的:

The SciPy library depends on NumPy, which provides convenient and fast N-dimensional array manipulation.

SciPy 库依赖于 NumPy,它提供了方便快捷的 N 维数组操作。

So, try installing numpypackage for python as you did with scipy.

因此,尝试numpy像使用scipy.

回答by E. V.

I recently got the same error when trying to load scipy in jupyter (python3.x, win10), although just having upgraded to numpy-1.13.3+mkl through pip. The solution was to simply upgrade the scipy package (from v0.19 to v1.0.0).

我最近在尝试在 jupyter(python3.x,win10)中加载 scipy 时遇到了同样的错误,尽管刚刚通过 pip 升级到 numpy-1.13.3+mkl。解决方案是简单地升级 scipy 包(从 v0.19 到 v1.0.0)。