在Windows上安装NumPy [英] Installing NumPy on Windows

查看:103
本文介绍了在Windows上安装NumPy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根本无法在Windows上安装NumPy.我不断收到此错误-

I'm simply unable to install NumPy on Windows. I keep getting this error -

PS C:\python27> pip install http://sourceforge.net/projects/numpy/file/NumPy/
Collecting http://sourceforge.net/projects/numpy/files/NumPy/
Downloading http://sourceforge.net/projects/numpy/files/NumPy/ (58kB)
100% |################################| 61kB 15kB/s
Cannot unpack file c:\users\toshiba\appdata\local\temp\pip-qev4rz-unpack\NumPy 
(downloaded from c:\users\toshiba\appdata\local\temp\pip-omripn-build, content-type: text/html; charset=utf-8); cannot detect archive format
Cannot determine archive format of c:\users\toshiba\appdata\local\temp\pip-omripn-build

我以前有Python 64位版本,但不确定NumPy版本是否与64位Python兼容.因此,我将其卸载并安装了32位Python版本.但是我仍然遇到相同的错误.尽管我的Python 32位版本运行正常.

I had Python 64 bit version earlier and I was not sure if NumPy version was compatible with 64 bit Python. So I uninstalled it and installed 32 bit Python version. But still I'm getting the same error. Though my Python 32 bit version is working fine.

我尝试了"pip install numpy",但最后却给我以下错误-

I tried "pip install numpy" but that give me the following error at the end -

C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'define_macros'

  warnings.warn(msg)

error: Unable to find vcvarsall.bat

----------------------------------------
Command "C:\Python27\python.exe -c "import setuptools,tokenize;__file__='c:\\users\\toshiba\\appdata\\local\\temp\\pip-build-hdhqex\\numpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'),__file__, 'exec'))" install --record c:\users\toshiba\appdata\local\temp\pip-x_6llm-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\toshiba\appdata\local\temp\pip-build-hdhqex\numpy

请告诉我我可能在做错什么.

Please tell me what I might be doing wrong.

推荐答案

一些解释

在第一种情况下,我没有检查,但我想pip直接下载与给定URL对应的资源:http://sourceforge.net/projects/numpy/file/NumPy/.服务器返回一个HTML文档,而pip需要一个存档文件.这样就行不通了.

Some explanations

In the first case, I didn't check but I guess that pip directly downloads the resource corresponding to the given URL: http://sourceforge.net/projects/numpy/file/NumPy/. The server returns a HTML document, while pip expects an archive one. So that can't work.

然后基本上有两种安装Python软件包的方法:

Then there are basically two ways to install Python packages:

  • 从源头开始尝试尝试
  • 来自预编译的软件包

第一种情况,您使用命令pip install numpy进行了尝试,但是由于此软件包包含本机代码,因此需要正确安装开发工具(在Windows上,我经常发现这样做很麻烦,但我做到了,因此这显然是可行的). error: Unable to find vcvarsall.bat的错误表示您未安装工具或正确设置了环境.

The first case, you tried it with the command pip install numpy, but since this package contains native code, it requires development tools to be installed properly (which I always found to be a pain in the neck to do on Windows, but I did it so it's clearly feasible). The error you have error: Unable to find vcvarsall.bat means you don't have the tools installed, or the environment properly set up.

对于第二种情况,您具有不同类型的预编译软件包:

For the second case, you have different kinds of pre-compiled packages:

  • 轮子,您也要同时安装pip
  • 安装程序,您在Windows上将其用作标准安装程序

对于这两者,您都需要检查二进制文件是否已针对您的Python体系结构(32位或64位)和版本严格编译.

For both, you need to check that the binary has been strictly compiled for your Python architecture (32 or 64 bits) and version.

您可以找到用于numpy的多个轮子: http://www.lfd.uci. edu/〜gohlke/pythonlibs/#numpy .要获得正确的体系结构,请为32位输入名称win32,为64位输入名称amd64.要获取正确的Python版本,请检查cpXX:第一个X是主要版本,第二个X是次要版本,因此例如cp27表示CPython 2.7.

You can find there several wheels for numpy: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy. To get the proper architecture, check in the name win32 for 32 bits and amd64 for 64 bits. To get the proper Python version, check cpXX: first X is major version, and second X is minor version, so for instance cp27 means CPython 2.7.

示例:pip install numpy‑1.9.2rc1+mkl‑cp27‑none‑win32.whl

免责声明:以下所有解释可能都不十分清楚.它们是在不同时刻进行的几次调查得出的,但是在我的配置中,它们导致了可行的解决方案.有些链接可能是无用的或多余的,但这就是我所指出的.所有这些都需要一些清洁,并且可能还需要概括.

DISCLAIMER: all the following explanations might not be quite clear. They result from several investigations at different moments, but in my configuration they led to a working solution. Some links might be useless, or redundant, but that's what I noted. All of this requires a bit of cleaning, and probably generalization too.

首先,您需要了解disutils-这是预安装的软件包,它以低于pip的级别处理软件包工作流(并且后者被后者使用)-将尝试使用严格遵循以下要求的编译器:与用于构建您所安装的Python机器的机器相匹配.

First, you need to understand that disutils - which is the pre-installed package which handles packages workflow at lower level than pip (and which is used by the latter) - will try to use a compiler that strictly matches the one that was used to build the Python machine you installed.

Python的官方发行版将Microsoft Visual C ++用于Microsoft Windows软件包.因此,在这种情况下,您将需要安装此编译器.

Official distributions of Python use Microsoft Visual C++ for Microsoft Windows packages. So you will need to install this compiler in this case.

Python使用此命令python -c "import sys; print(sys.version)"(或调用交互式shell)打印的字符串将如下所示:

The string printed by Python with this command python -c "import sys; print(sys.version)" (or when you invoke the interactive shell) will look like this:

3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]

方括号之间的最后一部分是编译器的标识部分.不幸的是,这不是很简单,您在那里有对应列表:

The last part between square brackets is the identification part of the compiler. Unfortunately, this is not quite straightforward, and you have correspondence lists there:

  • windows-什么版本的Visual Studio是在我的计算机上使用Python编译的吗? -堆栈溢出
    • windows - What version of Visual Studio is Python on my computer compiled with? - Stack Overflow
      • visual studio - Detecting compiler versions during compile time - Stack Overflow3
      • Pre-defined Compiler Macros / Wiki / Compilers
      • WinCvt - Windows Converter toolkit

      在我上面给出的示例中,这意味着 Microsoft Visual C ++ 2010 64位.

      In the example I gave above, this means Microsoft Visual C++ 2010 64 bits.

      您再也找不到适用于现代版本的Visual C ++独立软件包.因此,您将需要安装Windows SDK本身.

      You cannot find anymore a standalone package of Visual C++ for modern versions. So you will need to install the Windows SDK itself.

      以下是一些参考链接:

      • 从官方Microsoft下载中下载适用于Windows 7和.NET Framework 3.5 SP1的Microsoft Windows SDK.中心:用于Visual C ++ 15.00(Visual Studio 2008).对应于WinSDK 7.
      • 从官方Microsoft下载中心下载适用于Windows 7和.NET Framework 4的Microsoft Windows SDK :适用于Visual C ++ 16.00(Visual Studio 2010).对应于WinSDK 7.1.
      • 安装-我可以在哪里下载Visual C ++ Express的完整安装程序? -超级用户
        • Download Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 from Official Microsoft Download Center: for Visual C++ 15.00 (Visual Studio 2008). Corresponds to WinSDK 7.
        • Download Microsoft Windows SDK for Windows 7 and .NET Framework 4 from Official Microsoft Download Center: for Visual C++ 16.00 (Visual Studio 2010). Corresponds to WinSDK 7.1.
        • installation - where can I download the full installer for Visual C++ Express? - Super User
          • Visual Studio & co. downloads

          问题排查

          您在安装SDK时可能会出错: DDSet_Error: Patch Hooks: Missing required property 'ProductFamily': Setup cannot continue. DDSet_Warning: Setup failed while calling 'getDLLName'. System error: Cannot create a file when that file already exists.

          You might have an error at the installation of the SDK: DDSet_Error: Patch Hooks: Missing required property 'ProductFamily': Setup cannot continue. DDSet_Warning: Setup failed while calling 'getDLLName'. System error: Cannot create a file when that file already exists.

          已经在几个问题中对它们进行了报告:

          They have been reported in several questions already:

          • Windows 7 SDK Installation Failure
          • Error installing Windows 7 SDK 7.1 with VS2008, VS2010 Premium on Win 7 32bit

          作为解决方案,您可以检查以下链接: Windows SDK无法安装,返回码为5100

          As a solution, you can check this link: Windows SDK Fails to Install with Return Code 5100

          事情是删除Visual C ++可再发行组件的所有冲突版本(理解:SDK安装程序尝试自行安装的版本).

          The thing is to remove all conflicting (understand: the ones that the SDK installer tries to install itself) version of the Visual C++ redistributable.

          通常,您应该运行vsvarsall.bat(位于Visual Studio安装路径的VC文件夹内-示例:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat)来设置适当的环境变量,以免执行distutils尝试编译软件包时失败.

          Normally you should run vsvarsall.bat (located inside the VC folder of the installation path of Visual Studio - example: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat) to set up the proper environment variables so that the execution of distutils doesn't fail when trying to compile a package.

          此批处理脚本接受一个参数,该参数应设置所需的体系结构.但是,我看到,使用SDK的免费版本时,尝试其中的几个参数时缺少一些其他脚本.

          This batch script accepts a parameter, which should set the wanted architecture. However I saw that with the free versions of the SDK some additional scripts were missing when trying several of these parameters.

          只需说,如果要编译为32位体系结构,只需调用vsvarsall.bat应该可以.如果需要编译为64位,则可以直接调用SetEnv.cmd,位于SDK安装路径内的某个位置-例如:"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64.

          Just to say that if you are compiling for a 32 bits architecture, simply calling vsvarsall.bat should work. If you need to compile for 64 bits, you can directly call SetEnv.cmd, located somewhere under inside the SDK installation path - example: "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64.

          这篇关于在Windows上安装NumPy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆