A general overview of building NumPy from source is given here, with detailedinstructions for specific platforms given separately.
Building NumPy requires the following software installed:
Python 2.7.x, 3.4.x or newer
On Debian and derivatives (Ubuntu): python, python-dev (or python3-dev)
On Windows: the official python installer atwww.python.org is enough
Make sure that the Python package distutils is installed beforecontinuing. For example, in Debian GNU/Linux, installing python-devalso installs distutils.
Python must also be compiled with the zlib module enabled. This ispractically always the case with pre-packaged Pythons.
Compilers
To build any extension modules for Python, you’ll need a C compiler.Various NumPy modules use FORTRAN 77 libraries, so you’ll also need aFORTRAN 77 compiler installed.
Note that NumPy is developed mainly using GNU compilers. Compilers fromother vendors such as Intel, Absoft, Sun, NAG, Compaq, Vast, Portland,Lahey, HP, IBM, Microsoft are only supported in the form of communityfeedback, and may not work out of the box. GCC 4.x (and later) compilersare recommended.
Linear Algebra libraries
NumPy does not require any external linear algebra libraries to beinstalled. However, if these are available, NumPy’s setup script can detectthem and use them for building. A number of different LAPACK library setupscan be used, including optimized LAPACK libraries such as ATLAS, MKL or theAccelerate/vecLib framework on OS X.
Cython
To build development versions of NumPy, you’ll need a recent version ofCython. Released NumPy sources on PyPi include the C files generated fromCython code, so for released versions having Cython installed isn’t needed.
To install NumPy run:
pythonsetup.pyinstall
To perform an in-place build that can be run from the source folder run:
pythonsetup.pybuild_ext--inplace
The NumPy build system usessetuptools (from numpy 1.11.0, before that itwas plaindistutils) andnumpy.distutils.Usingvirtualenv should work as expected.
Note: for build instructions to do development work on NumPy itself, seeSetting up and using your development environment.
From NumPy 1.10.0 on it’s also possible to do a parallel build with:
python setup.py build -j 4 install --prefix $HOME/.local
This will compile numpy on 4 CPUs and install it into the specified prefix.to perform a parallel in-place build, run:
pythonsetup.pybuild_ext--inplace-j4
The number of build jobs can also be specified via the environment variableNPY_NUM_BUILD_JOBS.
The two most popular open source fortran compilers are g77 and gfortran.Unfortunately, they are not ABI compatible, which means that concretely youshould avoid mixing libraries built with one with another. In particular, ifyour blas/lapack/atlas is built with g77, youmust use g77 when buildingnumpy and scipy; on the contrary, if your atlas is built with gfortran, youmust build numpy/scipy with gfortran. This applies for most other caseswhere different FORTRAN compilers might have been used.
To build with gfortran:
pythonsetup.pybuild--fcompiler=gnu95
For more information see:
pythonsetup.pybuild--help-fcompiler
One relatively simple and reliable way to check for the compiler used to builda library is to use ldd on the library. If libg2c.so is a dependency, thismeans that g77 has been used. If libgfortran.so is a dependency, gfortranhas been used. If both are dependencies, this means both have been used, whichis almost always a very bad idea.
Usage of ATLAS and other accelerated libraries in NumPy can be disabledvia:
BLAS=NoneLAPACK=NoneATLAS=Nonepythonsetup.pybuild
Additional compiler flags can be supplied by setting theOPT,FOPT (for Fortran), andCC environment variables.When providing options that should improve the performance of the code ensurethat you also set-DNDEBUG so that debugging code is not executed.