libblas and liblapack issues and speed, with SciPy and Ubuntu

December 19, 2012 | categories: Python, Programming | View Comments

The problem

You've built from source a package that uses the linear algebra libraries BLAS and LAPACK, but now you're getting: cannot open shared object file: No such file or directory

In my case, I was trying to install SciPy from source using pip install scipy, but then ran into this issue when I tried to use it. I also ran into this other problem:

ImportError: scipy/linalg/ undefined symbol: clapack_sgesv

To fix it

  1. Make sure you've got libatlas3-base installed:

    sudo apt-get install libatlas3-base
  2. Make sure you're using the right implementation of, that is, the one that libatlas3-base provides. This implementation lives in /usr/lib/atlas-base/atlas/

    To do this, run the following command to set your system's default Atlas implementation:

    sudo update-alternatives --config

    An example of what this might produce, and what number you might need to enter:

    Selection      Path                                     Priority   Status
    * 0            /usr/lib/openblas-base/   40        auto mode
      1            /usr/lib/atlas-base/atlas/    35        manual mode
      2            /usr/lib/libblas/             10        manual mode
      3            /usr/lib/openblas-base/   40        manual mode
     Press enter to keep the current choice[*], or type selection number: 1
  3. Use from /usr/lib/atlas-base/atlas/ as your default:

    sudo update-alternatives --config

That's it. Now you shouldn't be getting the aforementioned errors anymore.

More information

The Debian Wiki has an overview of linear algebra libraries available, and it also describes how to use update-alternatives to switch between BLAS and LAPACK implementations.

Speed it up! Build an optimized Atlas for your architecture.

The README.Debian file of libatlas3-base explains:

Building your own optimized packages of Atlas is straightforward. Just get the sources of the package and its build-dependencies:

# apt-get source atlas
# apt-get build-dep atlas
# apt-get install devscripts dpkg-dev dch

and type the following from the atlas source subdir:

# fakeroot debian/rules custom

it should produce a package called:


which is optimized for the architecture Atlas has been built on. Then install the package using dpkg -i.

If you, like me, get this "classical" error when building Atlas:


then you'll need to read this: Your install dies with "unable to get timings in tolerance".

Lastly, you might need to remove any existing libopenblas installation from your system for the building of the Debian package to finish successfully:

sudo aptitude purge libopenblas-{base,dev}