Building from source#
Note
If you are only trying to install SciPy, we recommend using binaries - see Installation for details on that.
Note
If you are building SciPy in order to contribute to SciPy, please see instead the contributor building guide.
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.
To build SciPy from source to use SciPy, there are two steps: setting up system-level dependencies, and building SciPy itself.
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
conda env create -f environment.yml command.
If you want to use the system Python and pip, you will need:
C and C++ compilers (typically
gcc,g++).Python header files (typically a package named
python3-devorpython3-devel)BLAS and LAPACK libraries. OpenBLAS is the SciPy default; other variants include ATLAS and MKL.
pkg-configfor dependency detection.
To install SciPy build requirements, you can do:
sudo apt install -y gcc g++ libopenblas-dev liblapack-dev pkg-config 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.
To install SciPy build requirements, you can do:
sudo dnf install gcc python3-devel openblas-devel lapack-devel pkgconfig
Alternatively, you can do:
sudo dnf builddep 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.
To install SciPy build requirements, you can do:
sudo yum install gcc python3-devel openblas-devel lapack-devel pkgconfig
Alternatively, you can do:
sudo yum-builddep 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.
To install SciPy build requirements, you can do:
sudo pacman -S gcc openblas pkgconf
Install Apple Developer Tools. An easy way to do this is to open a terminal window, enter the command:
xcode-select --install
and follow the prompts. Apple Developer Tools includes Git, the Clang C/C++ compilers, and other development utilities that may be required.
Do not use the macOS system Python. Instead, install Python with the python.org installer or with a package manager like Homebrew, MacPorts or Fink.
The other system dependencies you need are BLAS and LAPACK libraries, and pkg-config. They’re easiest to install with Homebrew:
brew install openblas pkg-config
To allow the build tools to find OpenBLAS, you must run:
brew info openblas | grep PKG_CONFIG_PATH
This will give you a command starting with export PKG_CONFIG_PATH=, which
you must run.
Note
As of SciPy 1.14.0, we have added support for the Accelerate library for BLAS and LAPACK. It requires macOS 13.3 or greater. To build with Accelerate instead of OpenBLAS, see Selecting BLAS and LAPACK libraries.
A compatible set of C and C++ compilers is needed to build SciPy. You will need one of these sets of compilers:
clang-cl - recommended, because it’s easiest to install and is what we use for SciPy’s own CI and binaries
mingw-w64 compilers (
gcc,g++)Intel compilers (
icc)
Compared to macOS and Linux, building SciPy on Windows is a little more difficult, due to the need to set up these compilers. It is not possible to just call a one-liner on the command prompt as you would on other platforms.
First, install Microsoft Visual Studio - the 2019 Community Edition or any newer version will work (see the Visual Studio download site). This is needed even if you use the MinGW-w64 or Intel compilers, in order to ensure you have the Windows Universal C Runtime (the other components of Visual Studio are not needed when using Mingw-w64, and can be deselected if desired, to save disk space).
There are several sources of binaries for MinGW-w64. We recommend the RTools versions, which can be installed with Chocolatey (see Chocolatey install instructions here):
choco install rtools -y --no-progress --force --version=4.0.0.20220206
In case of issues, we recommend using the exact same version as used in the SciPy GitHub Actions CI jobs for Windows.
The MSVC installer does not put the compilers on the system path, and
the install location may change. To query the install location, MSVC
comes with a vswhere.exe command-line utility. And to make the
C/C++ compilers available inside the shell you are using, you need to
run a .bat file for the correct bitness and architecture (e.g., for
64-bit Intel CPUs, use vcvars64.bat).
For detailed guidance, see Use the Microsoft C++ toolset from the command line.
Similar to MSVC, the Intel compilers are designed to be used with an
activation script (Intel\oneAPI\setvars.bat) that you run in the
shell you are using. This makes the compilers available on the path.
For detailed guidance, see
Get Started with the Intel® oneAPI HPC Toolkit for Windows.
Note
Compilers should be on the system path (i.e., the PATH environment
variable should contain the directory in which the compiler executables
can be found) in order to be found, with the exception of MSVC which
will be found automatically if and only if there are no other compilers
on the PATH. You can use any shell (e.g., Powershell, cmd or
Git Bash) to invoke a build.
Building SciPy itself#
After all requisite system-level dependencies are installed,
you can follow the
Python Packaging User Guide on creating a virtual environment,
then build and install SciPy via pip:
# To build the latest stable release:
pip install scipy --no-binary scipy
# To build a development version, you need a local clone of the SciPy git repository:
git clone https://github.com/scipy/scipy.git
cd scipy
git submodule update --init
pip install .
If you are using a conda environment, pip is still the tool you use to
invoke a from-source build of SciPy. It is important to always use the
--no-build-isolation flag to the pip install command, to avoid
building against a numpy wheel from PyPI. In order for that to work you
must first install the remaining build dependencies into the conda
environment:
# Either install all SciPy dev dependencies into a fresh conda environment:
conda env create -f environment.yml
# Or, install only the required build dependencies (accurate at the time of writing):
conda install python numpy cython pythran pybind11 compilers openblas meson-python pkg-config
# To build the latest stable release:
pip install scipy --no-build-isolation --no-binary scipy
# To build a development version, you need a local clone of the SciPy git repository:
git clone https://github.com/scipy/scipy.git
cd scipy
git submodule update --init
pip install . --no-build-isolation
Customizing builds#
See the following pages for guidance on various customization options.
Background information#
See the following pages for background information on how the SciPy build works, and links to up-to-date guides for generic Python build & packaging documentation that is relevant.