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
Installing numpy for Windows 10: Importing the multiarray numpy extension module failed
提问by Mark Miller
I am new to Python
and 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 10
on a 64-bit machine and have installed Python 2.7.13
from https://www.python.org/downloads/windows/
首先,我认为我应该提供系统和版本详细信息并描述我所做的。我Windows 10
在 64 位机器上运行并Python 2.7.13
从https://www.python.org/downloads/windows/安装
I have also installed Anaconda
, also for Python 2.7
and a 64-bit machine, downloaded from here https://www.continuum.io/downloads. Anaconda
runs Python 2.7.12
, rather than Python 2.7.13
. When I type import numpy
inside the Anaconda
GUI IPython
no errors or warnings appear. Nevertheless, I have the impression running numpy
from inside Python 2.7.13
using IDLE (Python GUI)
might be computationally faster. Python 2.7.13
appears first in my Path statement.
我也安装了Anaconda
,也Python 2.7
和一个64位的机器,从这里下载https://www.continuum.io/downloads。 Anaconda
运行Python 2.7.12
,而不是Python 2.7.13
. 当我import numpy
在Anaconda
GUI 中输入时,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.whl
from 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.whl
从http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype下载 遵循这篇文章的建议从Windows 上的轮格式安装 numpy(在此平台上不受支持的轮。)我重命名:
numpy-1.12.0rc2+mkl-cp27-cp27m-win_amd64.whl
to:
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 pip
typing:
然后我使用 Windows 命令窗口 (cmd) 更新pip
键入:
python -m pip install --upgrade pip
A message said pip
was 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 .whl
file 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 numpy
in Python 2.7.13
I open Python
and typed:
安装numpy
后Python 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 numpy
folders 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 Python
for about 24 hours and most of that time has been spent attempting to install numpy
into Python 2.7.13
. Mostly I use R
and know some C
. I have not attempted to install any other Python
libraries 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 小时,大部分时间都花在尝试安装numpy
到Python 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 numpy
if 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 numpy
and 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 numpy
installed for Python 2.7.13
on the Windows 10
64-bit computer using the following steps. I was able to install numpy
for 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.13
Windows 10
numpy
Python 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 Python
using 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 Python
that is downloaded from here (https://www.python.org/downloads/) is 32-bit.
我怀疑我原来的帖子中的主要问题可能是因为没有意识到Python
从这里下载的默认版本(https://www.python.org/downloads/)是 32 位的。
For installing numpy
on 32-bit Python 2.7.13
用于numpy
在 32 位上安装Python 2.7.13
uninstalled
Anaconda
removed
Anaconda
fromUser Variables
in theEnvironment Variables
windowinstalled
Python 2.7.13
from the official Python website: https://www.python.org/in command window typed:
C:\users\general1>cd:\python27
Attempted to update
pip
in command window althoughpip
was already up to date:python -m pip install -U pip
in command window used the following command, which returned a huge number of errors:
pip install numpy
in command window typed:
python -m pip install numpy
已卸载
Anaconda
除去
Anaconda
从User Variables
在Environment Variables
窗口Python 2.7.13
从 Python 官方网站安装:https: //www.python.org/在命令窗口中输入:
C:\users\general1>cd:\python27
尝试
pip
在命令窗口中更新虽然pip
已经是最新的:python -m pip install -U pip
在命令窗口中使用了以下命令,该命令返回了大量错误:
pip 安装 numpy
在命令窗口中输入:
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
Opened
Python 2.7.13
and typed:import numpy
打开
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 numpy
was 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 numpy
was installed although my Python
is 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 Python
I accidentally installed a 32-bit version the last time. I can try installing Python
again 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.13
I am to click on the following on the official Python
webpage (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.whl
was 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 numpy
on 64-bit Python 2.7.13
用于numpy
在 64 位上安装Python 2.7.13
The steps above worked for installing numpy
for what turned out to be a 32-bit version of Python 2.7.13
.
上述步骤适用于安装numpy
32 位版本的Python 2.7.13
.
To install numpy for a 64-bit version of Python 2.7.13
I used the following steps:
要为 64 位版本安装 numpy,Python 2.7.13
我使用了以下步骤:
uninstall
Python 2.7.13
Download:
python-2.7.13.amd64.msi
by clicking on:Download Windows x86-64 MSI installer
from here: https://www.python.org/downloads/windows/in command window typed:
C:\users\general1>cd:\python27
Attempted to update
pip
in command window althoughpip
was already up to date:python -m pip install -U pip
in command window used the following command, which this time did not return any errors:
pip install numpy
卸载
Python 2.7.13
下载:
python-2.7.13.amd64.msi
点击:Download Windows x86-64 MSI installer
从这里:https: //www.python.org/downloads/windows/在命令窗口中输入:
C:\users\general1>cd:\python27
尝试
pip
在命令窗口中更新虽然pip
已经是最新的:python -m pip install -U pip
在命令窗口中使用了以下命令,这次没有返回任何错误:
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
Opened
Python 2.7.13
and typed:import numpy
打开
Python 2.7.13
并输入:导入 numpy
No errors or warnings were returned.
没有返回错误或警告。
Checked whether
numpy
was 64-bit or 32-bit. It was 64-bit.import numpy.distutils.system_info as sysinfo
sysinfo.platform_bits
64
检查
numpy
是 64 位还是 32 位。它是 64 位的。导入 numpy.distutils.system_info 作为 sysinfo
sysinfo.platform_bits
64
For installing numpy
wheel files in Python 2.7.13
用于安装numpy
车轮文件Python 2.7.13
After installing numpy
I tried to install scipy
and 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:
我做了以下事情:
Uninstalled
Python 2.7.13
Installed
Visual Studio Community 2017 RC
as described by drewid (here: Windows Scipy Install: No Lapack/Blas Resources Found)Installed
VCForPython27.msi
also as described by drewid.
已卸载
Python 2.7.13
Visual Studio Community 2017 RC
按照drewid 的描述安装(此处:Windows Scipy 安装:未找到 Lapack/Blas 资源)VCForPython27.msi
也按照drewid 的描述安装。
Then I received a scipy
error cannot import name NUMPY_MKL
mentioned here (ImportError: cannot import name NUMPY_MKL).
然后我收到这里提到的scipy
错误cannot import name NUMPY_MKL
(ImportError: cannot import name NUMPY_MKL)。
I downloaded the files numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
and scipy-0.18.1-cp27-cp27m-win_amd64.whl
from 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:
然后我:
uninstall
Python 2.7.13
Reinstall
Python 2.7.13
usingpython-2.7.13.amd64.msi
Installed
numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
from 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
Installed
scipy-0.18.1-cp27-cp27m-win_amd64.whl
from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpyusing the following line in the command windowpip install scipy-0.18.1-cp27-cp27m-win_amd64.whl
卸载
Python 2.7.13
重新安装
Python 2.7.13
使用python-2.7.13.amd64.msi
使用命令窗口中的以下行
numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
从http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy安装:pip 安装 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安装pip 安装 scipy-0.18.1-cp27-cp27m-win_amd64.whl
Both numpy
and scipy
can now import inside Python 2.7.13
numpy
和scipy
现在都可以导入里面Python 2.7.13
Note that I placed scipy-0.18.1-cp27-cp27m-win_amd64.whl
and numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
in the folder c:\Python27
prior to using the aforementioned pip
commands.
请注意,我在使用上述命令之前将scipy-0.18.1-cp27-cp27m-win_amd64.whl
和numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl
放在文件夹中。c:\Python27
pip
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:
我通过以下步骤解决了这个问题:
- Creating and activating a new
conda
environment - Installing
numpy
within the environment - Then using this environment for my project
- 创建和激活新
conda
环境 numpy
在环境中安装- 然后在我的项目中使用这个环境
I was using PyCharm
so to execute (3), I just set the project interpreter to the Python interpreter in the new environment I created in (1).
我使用PyCharm
so来执行(3),我只是在我在(1)中创建的新环境中将项目解释器设置为Python解释器。