Python 为 Windows 10 安装 numpy:导入多阵列 numpy 扩展模块失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41664756/
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-20 01:24:07  来源:igfitidea点击:

Installing numpy for Windows 10: Importing the multiarray numpy extension module failed

pythonarrayspython-2.7numpypython-import

提问by Mark Miller

I am new to Pythonand am attempting unsuccessfully to install numpy. The current problem is an error message reading, in part, Importing the multiarray numpy extension module failed. I cannot locate this error message on the internet and am asking for help. The complete error message is at the bottom of this post.

我是新手Python,正在尝试安装numpy. 当前的问题是错误消息读取,部分是Importing the multiarray numpy extension module failed。我在 Internet 上找不到此错误消息,正在寻求帮助。完整的错误消息在这篇文章的底部。

First I thought I should provide system and version details and describe what I have done. I am running Windows 10on a 64-bit machine and have installed Python 2.7.13from https://www.python.org/downloads/windows/

首先,我认为我应该提供系统和版本详细信息并描述我所做的。我Windows 10在 64 位机器上运行并Python 2.7.13https://www.python.org/downloads/windows/安装

I have also installed Anaconda, also for Python 2.7and a 64-bit machine, downloaded from here https://www.continuum.io/downloads. Anacondaruns Python 2.7.12, rather than Python 2.7.13. When I type import numpyinside the AnacondaGUI IPythonno errors or warnings appear. Nevertheless, I have the impression running numpyfrom inside Python 2.7.13using IDLE (Python GUI)might be computationally faster. Python 2.7.13appears first in my Path statement.

我也安装了Anaconda,也Python 2.7和一个64位的机器,从这里下载https://www.continuum.io/downloadsAnaconda运行Python 2.7.12,而不是Python 2.7.13. 当我import numpyAnacondaGUI 中输入时,IPython不会出现错误或警告。尽管如此,我的印象是numpy从内部运行Python 2.7.13使用IDLE (Python GUI)可能计算速度更快。 Python 2.7.13首先出现在我的 Path 语句中。

I downloaded numpy-1.12.0rc2+mkl-cp27-cp27m-win_amd64.whlfrom http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpypeFollowing suggestions from this post installing numpy from wheel format on windows ( not a supported wheel on this platform.)I renamed:

numpy-1.12.0rc2+mkl-cp27-cp27m-win_amd64.whlhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype下载 遵循这篇文章的建议从Windows 上的轮格式安装 numpy(在此平台上不受支持的轮。)我重命名:

numpy-1.12.0rc2+mkl-cp27-cp27m-win_amd64.whlto: numpy-1.12.0rc2+mkl-cp27-none-win32.whl

numpy-1.12.0rc2+mkl-cp27-cp27m-win_amd64.whl到: numpy-1.12.0rc2+mkl-cp27-none-win32.whl

manually by clicking on the name and editing it. The renamed file is in the folder C:\Python27

通过单击名称并对其进行编辑来手动进行。重命名的文件在文件夹中C:\Python27

Then I used the Windows command window (cmd) to update piptyping:

然后我使用 Windows 命令窗口 (cmd) 更新pip键入:

python -m pip install --upgrade pip

A message said pipwas already up-to-date.

一条消息说pip已经是最新的。

Then I typed the following in the cmd window:

然后我在 cmd 窗口中输入以下内容:

pip install numpy-1.12.0rc2+mkl-cp27-none-win32.whl

A message said: Successfully installed numpy-1.12.0rc2+mkl. (Prior to doing this I attempted to install the .whlfile using its original name and received an error that the file was not for my platform.)

一条消息说:Successfully installed numpy-1.12.0rc2+mkl。(在此之前,我尝试.whl使用其原始名称安装该文件,但收到一个错误,指出该文件不适用于我的平台。)

After installing numpyin Python 2.7.13I open Pythonand typed:

安装numpyPython 2.7.13我打开Python并输入:

import numpy

Here is the complete error message that was returned:

这是返回的完整错误消息:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import numpy
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    raise ImportError(msg)
ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Numerous numpyfolders and files now appear inside C:\Python27

许多numpy文件夹和文件现在出现在里面C:\Python27

I also tried the following two commands and received the messages shown:

我还尝试了以下两个命令并收到了显示的消息:

>>> pip show numpy
SyntaxError: invalid syntax
>>> git clean -xdf
SyntaxError: invalid syntax
>>> 

Sorry that this post is so long, but I do not know which of the above details might be most helpful in diagnosing the problem. I have only been using Pythonfor about 24 hours and most of that time has been spent attempting to install numpyinto Python 2.7.13. Mostly I use Rand know some C. I have not attempted to install any other Pythonlibraries or packages. Perhaps I am missing dependencies required by numpy. Thank you for any advice or assistance with this problem. If I can provide additional information please let me know. Sorry if this is a duplicate.

抱歉,这篇文章太长了,但我不知道上述哪些细节可能对诊断问题最有帮助。我只使用Python了大约 24 小时,大部分时间都花在尝试安装numpyPython 2.7.13. 大多数情况下,我使用R并了解一些C. 我没有尝试安装任何其他Python库或包。也许我缺少numpy. 感谢您对此问题的任何建议或帮助。如果我能提供更多信息,请告诉我。对不起,如果这是重复的。

回答by Samyak Upadhyay

In my case this issue was related to numpy. So, I removed the numpy and again installed it. To remove numpy if you already have conda environment can we done by conda remove numpyif this command is removing some other packages also which are dependent on numpy then in the same environment if pip is installed, numpy can be removed using pip pip uninstall numpyand to again download it use pip install numpy. This should probably fix your error.

就我而言,这个问题与 numpy. 所以,我删除了 numpy 并再次安装了它。要删除 numpy 如果您已经拥有 conda 环境,我们可以通过conda remove numpy如果此命令删除一些其他依赖于 numpy 的包,然后在同一环境中(如果安装了 pip),可以使用 pip 删除 numpypip uninstall numpy并再次下载它使用pip install numpy. 这应该可以解决您的错误。

回答by Mark Miller

I seem to have gotten numpyinstalled for Python 2.7.13on the Windows 1064-bit computer using the following steps. I was able to install numpyfor either a 32-bit or a 64-bit version of Python 2.7.13. Instructions for both are provided.

我似乎已经使用以下步骤在64 位计算机上numpy安装了 for 。我能够为32 位或 64 位版本的. 提供了两者的说明。Python 2.7.13Windows 10numpyPython 2.7.13

At the top of this answer are my instructions for 32-bit Python.
In the middle are my instructions for 64-bit Python. At the bottom are my instructions for 64-bit Pythonusing a wheel file.

在这个答案的顶部是我对 32-bit 的说明Python
中间是我对 64 位的说明Python。底部是我对 64 位Python使用轮文件的说明。

I suspect the primary problem in my original post may have arisen from not realizing that apparently the default version of Pythonthat is downloaded from here (https://www.python.org/downloads/) is 32-bit.

我怀疑我原来的帖子中的主要问题可能是因为没有意识到Python从这里下载的默认版本(https://www.python.org/downloads/)是 32 位的。

For installing numpyon 32-bit Python 2.7.13

用于numpy在 32 位上安装Python 2.7.13

  1. uninstalled Anaconda

  2. removed Anacondafrom User Variablesin the Environment Variableswindow

  3. installed Python 2.7.13from the official Python website: https://www.python.org/

  4. in command window typed:

    C:\users\general1>cd:\python27

  5. Attempted to update pipin command window although pipwas already up to date:

    python -m pip install -U pip

  6. in command window used the following command, which returned a huge number of errors:

    pip install numpy

  7. in command window typed:

    python -m pip install numpy

  1. 已卸载 Anaconda

  2. 除去AnacondaUser VariablesEnvironment Variables窗口

  3. Python 2.7.13从 Python 官方网站安装:https: //www.python.org/

  4. 在命令窗口中输入:

    C:\users\general1>cd:\python27

  5. 尝试pip在命令窗口中更新虽然pip已经是最新的:

    python -m pip install -U pip

  6. 在命令窗口中使用了以下命令,该命令返回了大量错误:

    pip 安装 numpy

  7. 在命令窗口中输入:

    python -m pip 安装 numpy

Step 7 seems to have worked. It returned the following message:

第 7 步似乎奏效了。它返回了以下消息:

C:\Python27>python -m pip install numpy
Collecting numpy
  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) 
  after connection broken by 'ProtocolError('Connection aborted.',
  error(10054, 'An existing connection was forcibly 
  closed by the remote host'))': /simple/numpy/
  Downloading numpy-1.12.0-cp27-none-win32.whl (6.6MB)
    100% |################################| 6.6MB 64kB/s
Installing collected packages: numpy
Successfully installed numpy-1.12.0
  1. Opened Python 2.7.13and typed:

    import numpy

  1. 打开Python 2.7.13并输入:

    导入 numpy

Only the command prompt was returned. No errors or warnings were issued.

仅返回命令提示符。没有发出错误或警告。

I have not yet tried to use any code that requires numpy, but at least it seems to have been installed.

我还没有尝试使用任何需要 的代码numpy,但至少它似乎已安装。

Step 7 says that a 32-bit file was downloaded:

步骤 7 表示下载了 32 位文件:

numpy-1.12.0-cp27-none-win32.whl

I do not know whether a 32-bit version of numpywas installed or a 64-bit version. Perhaps the file is a 64-bit version that was renamed to say it was a 32-bit version as described in my question.

我不知道numpy是安装了 32 位版本还是 64 位版本。也许该文件是一个 64 位版本,已重命名为 32 位版本,如我的问题中所述。

I typed in Python(from Do I have Numpy 32 bit or 64 bit?):

我输入了Python(从Do I have Numpy 32 bit or 64 bit?):

import numpy.distutils.system_info as sysinfo
sysinfo.platform_bits
32

So, it seems a 32-bit version of numpywas installed although my Pythonis supposed to be a 64-bit version (from here: How do I determine if my python shell is executing in 32bit or 64bit mode on OS X?):

所以,numpy虽然我Python的应该是 64 位版本,但似乎安装了 32位版本(从这里:如何确定我的 python shell 在 OS X 上以 32 位还是 64 位模式执行?):

import platform
platform.architecture()[0]
'32bit'

Perhaps in all of the installing and uninstalling of PythonI accidentally installed a 32-bit version the last time. I can try installing Pythonagain and use the intended 64-bit version this time. Hopefully the same steps above will still work.

也许在所有的安装和卸载中,Python我上次不小心安装了 32 位版本。Python这次我可以尝试再次安装并使用预期的 64 位版本。希望上述相同的步骤仍然有效。

Perhaps if I want a 64-bit version of Python 2.7.13I am to click on the following on the official Pythonwebpage (here: https://www.python.org/downloads/windows/):

也许如果我想要一个 64 位版本的Python 2.7.13我在官方Python网页上点击以下内容(这里:https: //www.python.org/downloads/windows/):

Download Windows x86-64 MSI installer

instead of on the prominent (https://www.python.org/downloads/):

而不是突出的(https://www.python.org/downloads/):

Download Python 2.7.13

I am also curious to know from where the file numpy-1.12.0-cp27-none-win32.whlwas downloaded. I will provide that too if I find out. Maybe it was downloaded from here: https://pypi.python.org/pypi/numpy

我也很想知道文件numpy-1.12.0-cp27-none-win32.whl是从哪里下载的。如果我发现,我也会提供。也许它是从这里下载的:https: //pypi.python.org/pypi/numpy

For installing numpyon 64-bit Python 2.7.13

用于numpy在 64 位上安装Python 2.7.13

The steps above worked for installing numpyfor what turned out to be a 32-bit version of Python 2.7.13.

上述步骤适用于安装numpy32 位版本的Python 2.7.13.

To install numpy for a 64-bit version of Python 2.7.13I used the following steps:

要为 64 位版本安装 numpy,Python 2.7.13我使用了以下步骤:

  1. uninstall Python 2.7.13

  2. Download: python-2.7.13.amd64.msiby clicking on: Download Windows x86-64 MSI installerfrom here: https://www.python.org/downloads/windows/

  3. in command window typed:

    C:\users\general1>cd:\python27

  4. Attempted to update pipin command window although pipwas already up to date:

    python -m pip install -U pip

  5. in command window used the following command, which this time did not return any errors:

    pip install numpy

  1. 卸载 Python 2.7.13

  2. 下载:python-2.7.13.amd64.msi点击:Download Windows x86-64 MSI installer从这里:https: //www.python.org/downloads/windows/

  3. 在命令窗口中输入:

    C:\users\general1>cd:\python27

  4. 尝试pip在命令窗口中更新虽然pip已经是最新的:

    python -m pip install -U pip

  5. 在命令窗口中使用了以下命令,这次没有返回任何错误:

    pip 安装 numpy

which returned:

返回:

C:\Python27>pip install numpy
Collecting numpy
  Downloading numpy-1.12.0-cp27-none-win_amd64.whl (7.5MB)
    100% |################################| 7.5MB 63kB/s
Installing collected packages: numpy
Successfully installed numpy-1.12.0
  1. Opened Python 2.7.13and typed:

    import numpy

  1. 打开Python 2.7.13并输入:

    导入 numpy

No errors or warnings were returned.

没有返回错误或警告。

  1. Checked whether numpywas 64-bit or 32-bit. It was 64-bit.

    import numpy.distutils.system_info as sysinfo

    sysinfo.platform_bits

    64

  1. 检查numpy是 64 位还是 32 位。它是 64 位的。

    导入 numpy.distutils.system_info 作为 sysinfo

    sysinfo.platform_bits

    64

For installing numpywheel files in Python 2.7.13

用于安装numpy车轮文件Python 2.7.13

After installing numpyI tried to install scipyand received an error: numpy.distutils.system_info.NotFoundError: no lapack/blas resources found(described here Windows Scipy Install: No Lapack/Blas Resources Found).

安装后,numpy我尝试安装scipy并收到错误:(numpy.distutils.system_info.NotFoundError: no lapack/blas resources found此处描述Windows Scipy 安装:未找到 Lapack/Blas 资源)。

I did the following:

我做了以下事情:

  1. Uninstalled Python 2.7.13

  2. Installed Visual Studio Community 2017 RCas described by drewid (here: Windows Scipy Install: No Lapack/Blas Resources Found)

  3. Installed VCForPython27.msialso as described by drewid.

  1. 已卸载 Python 2.7.13

  2. Visual Studio Community 2017 RC按照drewid 的描述安装(此处:Windows Scipy 安装:未找到 Lapack/Blas 资源

  3. VCForPython27.msi也按照drewid 的描述安装。

Then I received a scipyerror cannot import name NUMPY_MKLmentioned here (ImportError: cannot import name NUMPY_MKL).

然后我收到这里提到的scipy错误cannot import name NUMPY_MKLImportError: cannot import name NUMPY_MKL)。

I downloaded the files numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whland scipy-0.18.1-cp27-cp27m-win_amd64.whlfrom here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpyas suggested by VMAtm.

我下载的文件numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl,并scipy-0.18.1-cp27-cp27m-win_amd64.whl从这里:http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy通过VMAtm的建议。

Then I:

然后我:

  1. uninstall Python 2.7.13

  2. Reinstall Python 2.7.13using python-2.7.13.amd64.msi

  3. Installed numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whlfrom http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpyusing the following line in the command window:

    pip install numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl

  4. Installed scipy-0.18.1-cp27-cp27m-win_amd64.whlfrom http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpyusing the following line in the command window

    pip install scipy-0.18.1-cp27-cp27m-win_amd64.whl

  1. 卸载 Python 2.7.13

  2. 重新安装Python 2.7.13使用python-2.7.13.amd64.msi

  3. 使用命令窗口中的以下行numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whlhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy安装:

    pip 安装 numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl

  4. 在命令窗口中使用以下行scipy-0.18.1-cp27-cp27m-win_amd64.whlhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy安装

    pip 安装 scipy-0.18.1-cp27-cp27m-win_amd64.whl

Both numpyand scipycan now import inside Python 2.7.13

numpyscipy现在都可以导入里面Python 2.7.13

Note that I placed scipy-0.18.1-cp27-cp27m-win_amd64.whland numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whlin the folder c:\Python27prior to using the aforementioned pipcommands.

请注意,我在使用上述命令之前将scipy-0.18.1-cp27-cp27m-win_amd64.whlnumpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl放在文件夹中。c:\Python27pip

C:\>cd\Python27

C:\Python27>pip install numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
Processing c:\python27\numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
Installing collected packages: numpy
Successfully installed numpy-1.12.0+mkl

C:\Python27>pip install scipy-0.18.1-cp27-cp27m-win_amd64.whl
Processing c:\python27\scipy-0.18.1-cp27-cp27m-win_amd64.whl
Installing collected packages: scipy
Successfully installed scipy-0.18.1

C:\Python27>

回答by Colin Helms

This issue was discussed extensively over on https://github.com/numpy/numpy/issues/9272with a workaround solution which worked for me. It's pertinent to the Anaconda environment I believe you have.

这个问题在https://github.com/numpy/numpy/issues/9272上进行了广泛的讨论,并提供了一个对我有用的变通解决方案。我相信这与 Anaconda 环境有关。

Quoting: tobigithub commented on Jul 23, 2017. @njsmith thank you, I just confirmed using a VM on a clean Windows 10 system that has never seen Intel MKL DLLs, numpy or conda, all things are fine and numpy works. I am just puzzled how numpy suddenly stopped working, could be third parties. Probably needs some more digging, lets see what we can find out to make numpy ironclad to any dependency issue.

引用:tobigithub 于 2017 年 7 月 23 日发表评论。@njsmith 谢谢,我刚刚确认在从未见过英特尔 MKL DLL、numpy 或 conda 的干净 Windows 10 系统上使用 VM,一切都很好,numpy 工作正常。我只是很困惑 numpy 是如何突然停止工作的,可能是第三方。可能需要更多的挖掘,让我们看看我们能找到什么来使 numpy 铁定地解决任何依赖问题。

The solution is indeed related to some DLL depencency issues under WIN with Intel MKL libraries the numpy import error was under python 3.6.2 and numpy 1.13.1 :

该解决方案确实与 WIN 下的一些 DLL 依赖问题有关,使用 Intel MKL 库 numpy 导入错误在 python 3.6.2 和 numpy 1.13.1 下:

"import numpy" numpy\core_init_.py", line 16, in from . import multiarray ImportError: DLL load failed: The specified procedure could not be found.

"import numpy" numpy\core_init_.py", line 16, in from . import multiarray ImportError: DLL load failed: The specified procedure could not be found.

The quick and dirty solution is to copy all Intel mkl*.dll libraries from the specific environments (env) subfolder (seen at stackoverflow)

快速而肮脏的解决方案是从特定环境 (env) 子文件夹中复制所有英特尔 mkl*.dll 库(见 stackoverflow)

<\Library\bin> to <\Lib\site-packages\numpy\core>

<\Library\bin> 到 <\Lib\site-packages\numpy\core>

04/13/2017  12:50 AM        30,277,392 mkl_avx.dll
04/13/2017  12:50 AM        38,253,840 mkl_avx2.dll
04/13/2017  12:50 AM        42,234,640 mkl_avx512.dll
04/13/2017  12:50 AM        45,722,896 mkl_avx512_mic.dll
04/13/2017  12:50 AM        25,369,360 mkl_core.dll
04/13/2017  12:50 AM        24,541,456 mkl_def.dll
04/13/2017  12:50 AM        24,506,640 mkl_intel_thread.dll
04/13/2017  12:50 AM        29,744,400 mkl_mc.dll
04/13/2017  12:50 AM        30,594,320 mkl_mc3.dll
04/13/2017  12:50 AM        12,567,824 mkl_rt.dll
04/13/2017  12:50 AM        11,388,688 mkl_sequential.dll
04/13/2017  12:50 AM        12,575,504 mkl_tbb_thread.dll
04/13/2017  12:50 AM        11,250,960 mkl_vml_avx.dll
04/13/2017  12:50 AM        11,463,952 mkl_vml_avx2.dll
04/13/2017  12:50 AM        10,285,840 mkl_vml_avx512.dll
04/13/2017  12:50 AM        11,692,304 mkl_vml_avx512_mic.dll
04/13/2017  12:50 AM         5,224,208 mkl_vml_cmpt.dll
04/13/2017  12:50 AM         5,345,552 mkl_vml_def.dll
04/13/2017  12:50 AM         9,477,904 mkl_vml_mc.dll
04/13/2017  12:50 AM         9,368,336 mkl_vml_mc2.dll
04/13/2017  12:50 AM         9,593,616 mkl_vml_mc3.dll

now numpy can be imported and runs fine.

现在 numpy 可以导入并运行良好。

回答by Sam

I fixed this problem with the following steps:

我通过以下步骤解决了这个问题:

  1. Creating and activating a new condaenvironment
  2. Installing numpywithin the environment
  3. Then using this environment for my project
  1. 创建和激活新conda环境
  2. numpy在环境中安装
  3. 然后在我的项目中使用这个环境

I was using PyCharmso to execute (3), I just set the project interpreter to the Python interpreter in the new environment I created in (1).

我使用PyCharmso来执行(3),我只是在我在(1)中创建的新环境中将项目解释器设置为Python解释器。