Building from source

Note

If you are only trying to install SciPy, we recommend using binaries - see Installation for details on that.

Building SciPy from source requires setting up system-level dependencies (compilers, BLAS/LAPACK libraries, etc.) first, and then invoking a build. The build may be done in order to install SciPy for local usage, develop SciPy itself, or build redistributable binary packages. And it may be desired to customize aspects of how the build is done. This guide will cover all these aspects. In addition, it provides background information on how the SciPy build works, and links to up-to-date guides for generic Python build & packaging documentation that is relevant.

System-level dependencies

SciPy uses compiled code for speed, which means you need compilers and some other system-level (i.e, non-Python / non-PyPI) dependencies to build it on your system.

Note

If you are using Conda, you can skip the steps in this section - with the exception of installing compilers for Windows or the Apple Developer Tools for macOS. All other dependencies will be installed automatically by the mamba env create -f environment.yml command.

Building SciPy from source

If you want to only install SciPy from source once and not do any development work, then the recommended way to build and install is to use pip. Otherwise, conda is recommended.

Note

If you don’t have a conda installation yet, we recommend using Mambaforge; any conda flavor will work though.

Building from source to use SciPy

Building from source for SciPy development

If you want to build from source in order to work on SciPy itself, first clone the SciPy repository:

git clone https://github.com/scipy/scipy.git
cd scipy
git submodule update --init

Then you want to do the following:

  1. Create a dedicated development environment (virtual environment or conda environment),

  2. Install all needed dependencies (build, and also test, doc and optional dependencies),

  3. Build SciPy with our dev.py developer interface.

Step (3) is always the same, steps (1) and (2) are different between conda and virtual environments:

To build SciPy in an activated development environment, run:

python dev.py build

This will install SciPy inside the repository (by default in a build-install directory). You can then run tests (python dev.py test), drop into IPython (python dev.py ipython), or take other development steps like build the html documentation or running benchmarks. The dev.py interface is self-documenting, so please see python dev.py --help and python dev.py <subcommand> --help for detailed guidance.

IDE support & editable installs

While the dev.py interface is our recommended way of working on SciPy, it has one limitation: because of the custom install location, SciPy installed using dev.py will not be recognized automatically within an IDE (e.g., for running a script via a “run” button, or setting breakpoints visually). This will work better with an in-place build (or “editable install”).

Editable installs are supported. It is important to understand that you may use either an editable install or dev.py in a given repository clone, but not both. If you use editable installs, you have to use pytest and other development tools directly instead of using dev.py.

To use an editable install, ensure you start from a clean repository (run git clean -xdf if you’ve built with dev.py before) and have all dependencies set up correctly as described higher up on this page. Then do:

# Note: the --no-build-isolation is important! meson-python will
# auto-rebuild each time SciPy is imported by the Python interpreter.
pip install -e . --no-build-isolation

# To run the tests for, e.g., the `scipy.linalg` module:
pytest scipy/linalg

When making changes to SciPy code, including to compiled code, there is no need to manually rebuild or reinstall. When you run git clean -xdf, which removes the built extension modules, remember to also uninstall SciPy with pip uninstall scipy.

See the meson-python documentation on editable installs for more details on how things work under the hood.

Customizing builds

Background information