Why should NumPy be installed via a binary package

2019-08-15 18:20发布

问题:

According to the NumPy documentation:

In most use cases the best way to install NumPy on your system is by using an installable binary package for your operating system.

But why can't it be installed just as easily using pip?

As I understand it, NumPy needs to compile something other than pure Python according to the target machine. How does this work? Does the binary package contain C source files and a C compiler? Or does it contain all the pre-compiled binaries, and just chooses the proper ones to install based on the operating system?

回答1:

The pip package just contains the numpy source distribution which includes extensions written in C, so in order to build it you'll need to have a working C compiler (and this certainly doesn't come pre-packaged with the numpy source). You'll also need a LAPACK library which, if you build it from source, will probably also require a FORTRAN 77 compiler.

How easy it is to install numpy via pip will depend greatly on what environment you're working in. Generally speaking it's pretty easy to set up the necessary toolchain if you're using Linux or OSX. It's usually Windows users that tend to suffer the most problems, due to the much poorer state of compiler support, so the usual recommendation is to install from a binary distribution. The Anaconda distribution and Christoph Gohlke's pre-built binaries are probably the two most popular options.

If you're a Windows user and you're feeling particularly adventurous/masochistic, there are also instructions for compiling numpy and scipy from source here.



回答2:

The most important reason is that you need some performant BLAS/LAPACK implementation. There is a lot of options, and if you don't know what you're doing, you're better of when someone chooses that for you.

Intel MKL is one of the better choices, but it's not completely free. Christoph Gohlke's binaries use it. Continuum Analytics is selling binaries built with MKL separately.



标签: python numpy pip