This is an archival dump of old wiki content --- see for current material

Building Scipy

Table of contents


The SciPy project provides two packages: NumPy (formerly known as core SciPy) and full SciPy. The NumPy package is a replacement of Numeric and should be installed before building the full SciPy package. Installing both packages is simple. In most cases simply executing

  python install

in the numpy and scipy directories will install each package. The rest of this document concentrates on configuring, building, installing, or/and using various external software that Scipy can use for extra power.

Note that to avoid problems, it can be a good idea to remove the local build directory (if any) and existing Scipy installations, before building and installing a new version built from sources. Also note that the use of pip and especially easy_install is not recommended, as these tools often have problems where the standard python install does not.


To build SciPy, Python version 2.6 or newer is required. Make sure that the Python package distutils is installed before continuing. For example, in Debian GNU/Linux, distutils is included in the python-dev package.

If while building SciPy, "error: pyconfig.h: No such file or directory" is encountered, ensure that Python is installed a directory that is different from its source.


To build any extension modules for Python, you'll need a C compiler.

Various SciPy modules use Fortran 77 libraries and some use C++, so you'll also need Fortran 77 and C++ compilers installed. The SciPy module Weave uses a C++ compiler at run time.

Note that SciPy is developed mainly using GNU compilers. Compilers from other vendors such as Intel, Absoft, Sun, NAG, Compaq, Vast, Porland, Lahey, HP, IBM are supported in the form of community feedback.

gcc 3.x compilers are recommended. Note that code compiled by the Intel Fortran Compiler (IFC) is not binary compatible with code compiled by g77. Therefore, when using IFC, all Fortran codes used in SciPy must be compiled with IFC. This also includes the LAPACK, BLAS, and ATLAS libraries. Using GCC for compiling C code is OK. IFC version 5.0 is not supported.

To build NumPy, only a C compiler is required.

If you see an error message

ImportError: /usr/lib/atlas/ undefined symbol: _gfortran_st_write_done

when building SciPy, it means that NumPy picked up the wrong Fortran compiler during build (e.g. ifort). Recompile NumPy using:

python build --fcompiler=gnu95

or whichever is appropriate (see python build --help-fcompiler).

Linear Algebra libraries

Various SciPy packages do linear algebra computations using the LAPACK routines. SciPy's scripts can use number of different LAPACK library setups, including optimized LAPACK libraries such as ATLAS or the Accelerate/vecLib framework on OS X. The following notes give detailed information on how to prepare the build environment so that SciPy's scripts can use whatever LAPACK library setup one has.

NumPy does not require any external linear algebra libraries to be installed. However, if these are available, NumPy's setup script can detect them and use them for building. If you do not plan to build the full SciPy then you can skip this section.

Building BLAS library from Netlib

Download BLAS sources from Netlib, build libfblas.a library, and set environment variable BLAS:

mkdir -p ~/src/
cd ~/src/
tar xzf blas.tgz
# NOTE: The selected fortran compiler must be consistent for BLAS, LAPACK, NumPy, and SciPy.
# For GNU compiler on 32-bit systems:
g77 -O2 -fno-second-underscore -c *.f                     # with g77
gfortran -O2 -std=legacy -fno-second-underscore -c *.f    # with gfortran
# OR for GNU compiler on 64-bit systems:
g77 -O3 -m64 -fno-second-underscore -fPIC -c *.f                     # with g77
gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c *.f    # with gfortran
# OR for Intel compiler:
ifort -FI -w90 -w95 -cm -O3 -unroll -c *.f
# Continue below irrespective of compiler:
ar r libfblas.a *.o
ranlib libfblas.a
rm -rf *.o
export BLAS=~/src/BLAS/libfblas.a

See the note at the end of the section below on building LAPACK.

Building LAPACK library from Netlib

Download LAPACK sources from Netlib, build libflapack.a library, and set environment variable LAPACK:

mkdir -p ~/src
tar xzf lapack.tgz
cd ~/src/LAPACK
cp INSTALL/          # on Linux with lapack-3.2.1 or newer
cp INSTALL/             # on Linux with older lapack
# Edit as follows:
# For GNU compiler on 32-bit Linux (these are the defaults):
OPTS = -O2
# OR for GNU compiler on 64-bit Linux:
OPTS = -O2 -m64 -fPIC
NOOPT = -m64 -fPIC
# OR for Absoft (8.x or later):
# OR for Intel Fortran compiler on Linux:
# Continue below irrespective of compiler:
make lapacklib
make clean
cp lapack_LINUX.a libflapack.a                 # on Linux
export LAPACK=~/src/LAPACK/libflapack.a

In the event that SciPy is unable to find the libf* names, a symbolic link can be made from these files to libblas.a and liblapack.a. NumPy is not expected to have this problem.

Further Instructions

More detailed platform-specific instructions for building and installing SciPy can be found on the Installing_SciPy page.

SciPy: Installing_SciPy/BuildingGeneral (last edited 2015-10-24 17:48:25 by anonymous)