Building from sources#

Note

If you are only trying to install SciPy, see Installation.

Build instructions for different operating systems and an FAQ.

System-level dependencies#

SciPy uses compiled code for speed, which means you might need extra dependencies to build it on your system.

Note

You can skip these steps if you are using conda, as these dependencies will be installed automatically.

If you want to use the system Python and pip, you will need:

  • C, C++, and Fortran compilers (typically gcc, g++, and gfortran).

  • Python header files (typically a package named python3-dev or python3-devel)

  • BLAS and LAPACK libraries. OpenBLAS is the SciPy default; other variants include ATLAS and MKL.

Note

These instructions have been tested on Ubuntu Linux 16.04, 18.04, and 20.04.

Python should be available in your system via the python3 command. To install the remaining system-level dependencies, run:

sudo apt install -y gcc g++ gfortran libopenblas-dev liblapack-dev pkg-config
sudo apt install -y python3-pip python3-dev

Alternatively, you can do:

sudo apt build-dep scipy

This command installs whatever is needed to build SciPy, with the advantage that new dependencies or updates to required versions are handled by the package managers.

See also Development environment guide (Ubuntu).

All further work should proceed in a virtual environment. Popular options include the standard library venv module or a separate virtualenv package.

  • The Cython and Pythran ahead-of-time compilers are also necessary, as is pybind11. It is recommended to install these packages with pip, because it is possible (even likely) that you need newer versions of these packages than the ones that are available in your Linux distribution.

If you are using conda, these dependencies can be installed in the conda environment itself. See Development environment guide (conda) for more details.

Detailed instructions#

Reference for build options#

SciPy has several tunable build-time options, which can be set.

Warning

This content is for the old numpy.distutils-based build and doesn’t apply to the Meson build (i.e., when building with python dev.py).

  • site.cfg: build-time library configuration file, see site.cfg.example for details.

  • Environment variables NPY_LAPACK_ORDER, NPY_BLAS_ORDER, OPENBLAS, ATLAS, etc., also controlling library configuration. See Numpy documentation for more details.

  • Environment variable NPY_USE_BLAS_ILP64=1: build using 64-bit integer size (ILP64) BLAS+LAPACK libraries.

    Note that even when this is set, SciPy requires also 32-bit integer size (LP64) BLAS+LAPACK libraries to be available and configured. This is because only some components in SciPy make use of the 64-bit capabilities.