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
I had a 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 a 32-bit Python version. But still I'm getting the same error. Though my Python 32-bit version is working fine.
I tried "pip install numpy", but that gave 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
What might I be doing wrong?
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.
Then there are basically two ways to install Python packages:
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
as wellFor both, you need to check that the binary has been strictly compiled for your Python architecture (32 or 64 bits) and version.
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.
Example: 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.
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.
Official distributions of Python use Microsoft Visual C++ for Microsoft Windows packages. So you will need to install this compiler in this case.
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:
In the example I gave above, this means Microsoft Visual C++ 2010 64 bits.
You cannot find anymore a standalone package of Visual C++ for modern versions. So you will need to install the Windows SDK itself.
Here are some reference links:
Troubleshooting
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:
As a solution, you can check this link: Windows SDK Fails to Install with Return Code 5100
The thing is to remove all conflicting (understand: the ones that the SDK installer tries to install itself) version of the Visual C++ redistributable.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With