A Comprehensive Guide to Resolving BLAS and LAPACK Dependencies for SciPy Installation

Dec 05, 2025 · Programming · 15 views · 7.8

Keywords: SciPy Installation | BLAS Dependencies | LAPACK Errors | Python Scientific Computing | Wheel Packages

Abstract: This article addresses the common BLAS and LAPACK dependency errors encountered during SciPy installation by providing a wheel-based solution. Through analysis of the root causes of pip installation failures, it details how to obtain pre-compiled wheel packages from third-party sources and provides step-by-step installation guidance. The article also compares different installation methods to help users choose the most appropriate strategy based on their needs.

In the Python scientific computing ecosystem, SciPy is a powerful library that relies on underlying linear algebra libraries BLAS and LAPACK for efficient numerical computations. However, many users encounter errors similar to the following when attempting to install SciPy via pip install scipy:

numpy.distutils.system_info.NotFoundError: no lapack/blas resources found

This error indicates that the system cannot find the necessary BLAS and LAPACK libraries. The fundamental reason is that pip defaults to compiling SciPy from source, and the compilation process requires these underlying libraries. For most users, manually configuring these libraries is both complex and time-consuming.

Why is SciPy Installation So Complex?

The complexity of SciPy stems from its dependencies. Unlike pure Python packages, SciPy contains C and Fortran code that requires compilation, and this code depends on system-level libraries like BLAS and LAPACK. When installing via pip, if these libraries are not pre-installed, the compilation process fails.

Users attempting to install BLAS and LAPACK directly also encounter problems:

pip install lapack
Collecting lapack
  Could not find a version that satisfies the requirement lapack

This occurs because BLAS and LAPACK are not Python packages but system libraries that cannot be installed directly via pip.

Solution Using Wheel Packages

The most effective solution is to use pre-compiled wheel packages. Wheels are Python's binary package format that include all necessary dependencies, eliminating the need for manual compilation. For Windows users, Christoph Gohlke maintains an excellent third-party repository providing pre-compiled wheel packages for many scientific computing packages.

The installation steps are as follows:

  1. Visit Gohlke's Python Extension Packages page
  2. Download the appropriate packages based on your Python version and system architecture:
    • First download the NumPy wheel package (e.g., numpy-1.19.5+mkl-cp39-cp39-win_amd64.whl)
    • Then download the SciPy wheel package (e.g., scipy-1.6.0-cp39-cp39-win_amd64.whl)
  3. Install the downloaded wheel packages using pip:
pip install numpy-1.19.5+mkl-cp39-cp39-win_amd64.whl
pip install scipy-1.6.0-cp39-cp39-win_amd64.whl

This method avoids the compilation process by directly using pre-compiled binaries, significantly simplifying the installation workflow.

Comparison of Alternative Installation Methods

Beyond using wheel packages, several other common installation methods exist:

Using Linux Package Managers

For Debian/Ubuntu systems, necessary dependencies can be installed via the system package manager:

sudo apt install libblas3 liblapack3 liblapack-dev libblas-dev gfortran

After installing these packages, pip install scipy typically succeeds. This approach is suitable for Linux users but requires system administrator privileges.

Using Anaconda or Miniconda

Anaconda and Miniconda are Python distributions specifically designed for scientific computing, containing SciPy and all its dependencies. Installation is straightforward:

conda install scipy

This method provides the most complete scientific computing environment, but the installation package is relatively large. Miniconda offers a lighter alternative, including only the conda package manager and Python, allowing users to install specific packages as needed.

Technical Principle Analysis

To understand why wheel packages solve this problem, it's essential to comprehend Python's package installation mechanism. When using pip install scipy, the default behavior is:

  1. Download SciPy's source package
  2. Run setup.py for compilation
  3. The compilation process requires linking to BLAS and LAPACK libraries
  4. If these libraries are not found, compilation fails

Wheel packages are pre-compiled binary packages containing already-compiled extension modules. Installation merely involves extracting files to the correct location, eliminating the compilation process. This removes dependencies on system libraries, making installation more reliable.

Taking SciPy's linear algebra module as an example, its C extension code needs to call BLAS and LAPACK functions. In wheel packages, these calls are already linked to specific implementations (such as MKL or OpenBLAS), freeing users from worrying about the linking process.

Practical Recommendations

Based on different usage scenarios, we recommend the following installation strategies:

Regardless of the chosen method, it's advisable to first create a clean Python environment to avoid conflicts with existing installations. For production environments, using Docker containers is recommended to ensure environmental consistency.

By understanding SciPy's dependency mechanisms and selecting appropriate installation methods, users can easily overcome installation obstacles and quickly begin scientific computing work.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.