SciPy

raw JSON →
1.17.1 verified Tue May 12 auth: no python install: verified quickstart: verified

SciPy is a Python library for scientific computing, offering modules for optimization, integration, interpolation, linear algebra, statistics, and more. The current version is 1.17.1, released on February 22, 2026, with a regular release cadence of approximately every 6 months.

pip install scipy
error Failed building wheel for scipy
cause SciPy's installation from source (which pip attempts if no pre-built wheel is available) requires a C/Fortran compiler toolchain on your system.
fix
Ensure you have numpy pre-installed and use a compatible Python version for which pre-built wheels exist, or install the necessary compiler tools (e.g., build-essential on Linux, Xcode Command Line Tools on macOS, Visual C++ build tools on Windows). Often, pip install --upgrade pip followed by pip install numpy scipy resolves it.
error Optimal parameters not found: The iteration is not making good progress, as measured by the improvement from the last ten iterations.
cause The `scipy.optimize.curve_fit` algorithm failed to converge to a stable solution, often due to poor initial guesses, ill-conditioned data, or an unsuitable model function.
fix
Provide better initial guesses for the parameters (p0), increase the maximum number of iterations (maxfev), or add bounds to the parameters (bounds).
error AttributeError: module 'scipy' has no attribute 'interp1d'
cause The `interp1d` function is part of the `scipy.interpolate` submodule, but the code attempted to access it directly from the top-level `scipy` module.
fix
Import interp1d from its correct submodule: from scipy.interpolate import interp1d.
error scipy.linalg.LinAlgError: Singular matrix
cause This error occurs when a linear algebra operation (like matrix inversion) is performed on a singular matrix, which has a determinant of zero and thus no unique inverse.
fix
Check the input matrix for linear dependencies or near-singularities. If solving a system, consider using a pseudo-inverse (numpy.linalg.pinv or scipy.linalg.pinv) or least squares (numpy.linalg.lstsq) instead of direct inversion.
error IntegrationWarning: The integral is probably divergent, or slowly convergent.
cause The `scipy.integrate.quad` function struggled to evaluate the integral, often indicating a singularity, discontinuity, or highly oscillatory behavior of the integrand within the integration range.
fix
Examine the integrand for singularities or problematic points within the integration interval. If known, specify singular points using the points argument in quad, split the integral, or adjust error tolerances (epsabs, epsrel).
breaking SciPy 1.17.1 requires Python 3.11 or higher.
fix Upgrade your Python installation to version 3.11 or later.
gotcha Ensure that NumPy is installed before SciPy, as SciPy depends on NumPy for array operations.
fix Install NumPy first using 'pip install numpy'.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.91s 230.6M
3.10 slim (glibc) - - 0.66s 222M
3.11 alpine (musl) - - 1.38s 245.8M
3.11 slim (glibc) - - 1.14s 235M
3.12 alpine (musl) - - 1.25s 231.8M
3.12 slim (glibc) - - 1.31s 221M
3.13 alpine (musl) - - 1.05s 230.5M
3.13 slim (glibc) - - 1.14s 220M
3.9 alpine (musl) - - 0.65s 232.8M
3.9 slim (glibc) - - 0.63s 229M

This example demonstrates how to compute the shortest path distances in a graph using SciPy's sparse graph module.

import numpy as np
from scipy.sparse.csgraph import shortest_path

# Create a sample graph as a 2D NumPy array
graph = np.array([[0, 1, 2], [1, 0, 0], [2, 0, 0]])

# Compute the shortest path distances
dist_matrix, predecessors = shortest_path(graph, return_predecessors=True)

print('Shortest path distance matrix:')
print(dist_matrix)