running librosa & numba on raspberry pi 3

11,262

Solution 1

As of writing, the latest Raspbian release has llvm-3.8, so per this github comment you need to install llvmlite v0.15.0 with numba v0.30.1. If you're on a different llvm then you will need to explore what versions of llvmlite and numba to use with that version of llvm. Here are the commands that got me set up to get a successful import librosa:

sudo apt install libblas-dev llvm python3-pip python3-scipy
virtualenv --system-site-packages -p python3 env
source env/bin/activate
pip install llvmlite==0.15.0
pip install numba==0.30.1
pip install librosa

Note I'm using virtualenv and dragging in scipy and numpy from the system packages, otherwise it's hard to get the fortran & c dependencies right plus those take ages to compile on a RPi. If you want to install system-wide then drop the 2nd and 3rd line and put sudo in front of the pip commands. I've also frozen my requirements in this requirements.txt file so if you download that then you can run a single command pip install -r requirements.txt

Solution 2

sudo pip install librosa==0.4.2 worked for me. There was warning yet works fine on Raspberry pi3 (OS:raspbian-jessie)

Solution 3

Thanks @MatthewBerryman, you got me over the hump! On the newest Raspian release (stretch) I was successful with the following after several hours of frustration of trying to get librosa installed on Raspian jessie (which my RPi3 came with). Having said this, the following procedure may also work with jessie.

First, update your system's package list and upgrade all your installed packages to their latest versions with the command:

sudo apt-get update
sudo apt-get dist-upgrade

Install Python science stack:

sudo pip3 install numpy --upgrade 
sudo apt-get install python3-pandas

(Also seems to install matplotlib, scipy)

sudo apt-get install python3-sklearn

Then, install the low-level virtual machine, LLVM (per @MatthewBerryman, I used llvm 3.8 and llvmlite 0.15.0, and not the newest combination where I couldn't find the packages.) After installing llvm-3.8, a symbolic link needs to be defined before installing llvmlite.

sudo apt-get install llvm-3.8
sudo ln -s /usr/bin/llvm-config-3.8 /usr/bin/llvm-config
sudo pip3 install llvmlite==0.15.0
sudo pip3 install numba==0.32.0

Numba is 0.32.0 because if it's the newest (0.36), it will not import because of an llvm mismatch, and if it's a lower version, the librosa install will upgrade it to the newest version.

Finally, install librosa:

sudo pip3 install librosa

However, when trying to import librosa, it still throws and error, namely

ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory

Googling this error indicated this would fix it:

sudo apt-get install libatlas-base-dev

And it did; however, I have no idea why.

To summarize, this procedure installs librosa, and there is no error when trying this:

...$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
...
>>>import librosa
>>>

Solution 4

If you have previously installed packages, either reboot with a fresh copy of OS or create a virtual environment, as suggested by others. Creating virtual env did not work at the first try for me, you might want to reboot to a fresh copy.

Then install virtualenv and create a new virtualenv.

Activate the virtualenv using python3.

sudo apt-get install llvm

You should get llvm 7.0.x

Then install a compatible llvmlite - this works for 7.0. Get the path by typing which llvm-config In my case it was /usr/bin/llvm-config

LLVM_CONFIG=/usr/bin/llvm-config pip3 install llvmlite==0.32

install dependencies

pip3 install numpy==1.16.1 numba==0.49
pip3 install librosa

If you get an error after trying to import librosa due to numpy, update dependencies

sudo apt-get install libatlas-base-dev

Credits to this tutorial

Share:
11,262
Admin
Author by

Admin

Updated on June 12, 2022

Comments

  • Admin
    Admin about 2 years

    I am trying to run librosa on my raspberry pi 3. After hours of searching through the internet I was finally able to install it but it still throws an error when I try to import it. First, I had problems to install the dependency llvmlite. I finally installed it with the following code: conda install -c numba llvmlite. I use python 3.4 build with miniconda.

    After llvmlite was installed I was able to install librosa with pip (not possible with conda)

    pi@raspberrypi:~ $ pip install librosa
    Collecting librosa
    Using cached https://www.piwheels.hostedpi.com/simple/librosa/librosa-
    0.5.1-py3-none-any.whl
    Requirement already satisfied: resampy>=0.1.2 in 
    ./miniconda3/lib/python3.4/site-packages (from librosa)
    Requirement already satisfied: scipy>=0.13.0 in 
    ...
    Installing collected packages: librosa
    Successfully installed librosa-0.5.1
    

    Apparently librosa is installed.

    pi@raspberrypi:~ $ pip list
    DEPRECATION: The default format will switch to columns in the future. 
    You can use --format=(legacy|columns) (or define a format=
    (legacy|columns) in your pip.conf under the [list] section) to disable 
    this warning.
    anaconda-client (1.0.2)
    audioread (2.1.5)
    awscli (1.11.170)
    boto3 (1.4.7)
    botocore (1.7.28)
    clyent (0.4.0)
    colorama (0.3.7)
    conda (3.16.0)
    conda-env (2.4.2)
    Cython (0.27.1)
    decorator (4.1.2)
    docutils (0.14)
    jmespath (0.9.3)
    joblib (0.11)
    librosa (0.5.1)
    llvmlite (0.7.0.dev0+21.gcda19bd.dirty)
    mock (2.0.0)
    numba (0.35.0)
    numpy (1.13.3)
    pbr (3.1.1)
    Pillow (2.9.0)
    pip (9.0.1)
    protobuf (3.4.0)
    pyasn1 (0.3.7)
    PyAudio (0.2.11)
    pycosat (0.6.1)
    pycrypto (2.6.1)    
    python-dateutil (2.6.1)
    pytz (2015.4)
    PyYAML (3.12)
    requests (2.7.0)
    resampy (0.2.0)
    rsa (3.4.2)
    s3transfer (0.1.11)
    scikit-learn (0.18.2)
    scipy (0.19.1)
    setuptools (18.1)
    six (1.11.0)
    tensorflow (1.1.0)
    Werkzeug (0.12.2)
    wheel (0.30.0)
    

    Trying to import librosa throws the following error though:

    pi@raspberrypi:~ $ python
    Python 3.4.3 |Continuum Analytics, Inc.| (default, Aug 21 2015, 00:53:08) 
    [GCC 4.6.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import librosa
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/pi/miniconda3/lib/python3.4/site-packages/librosa/__init__.py", line 12, in <module>
        from . import core
      File "/home/pi/miniconda3/lib/python3.4/site-packages/librosa/core/__init__.py", line 108, in <module>
        from .time_frequency import *  # pylint: disable=wildcard-import
      File "/home/pi/miniconda3/lib/python3.4/site-packages/librosa/core/time_frequency.py", line 10, in <module>
        from ..util.exceptions import ParameterError
      File "/home/pi/miniconda3/lib/python3.4/site-packages/librosa/util/__init__.py", line 70, in <module>
        from . import decorators
      File "/home/pi/miniconda3/lib/python3.4/site-packages/librosa/util/decorators.py", line 67, in <module>
        from numba.decorators import jit as optional_jit
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/__init__.py", line 12, in <module>
        from .special import typeof, prange
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/special.py", line 4, in <module>
        from .parfor import prange
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/parfor.py", line 20, in <module>
        from numba import array_analysis, postproc, typeinfer
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/array_analysis.py", line 9, in <module>
        from numba import ir, analysis, types, config, cgutils, typing
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/cgutils.py", line 22, in <module>
        true_bit = bool_t(1)
    TypeError: 'IntType' object is not callable
    >>> 
    

    Trying to import numba throws the following error:

    pi@raspberrypi:~ $ python
    Python 3.4.3 |Continuum Analytics, Inc.| (default, Aug 21 2015, 00:53:08) 
    [GCC 4.6.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numba
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/__init__.py", line 12, in <module>
        from .special import typeof, prange
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/special.py", line 4, in <module>
        from .parfor import prange
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/parfor.py", line 20, in <module>
        from numba import array_analysis, postproc, typeinfer
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/array_analysis.py", line 9, in <module>
        from numba import ir, analysis, types, config, cgutils, typing
      File "/home/pi/miniconda3/lib/python3.4/site-packages/numba/cgutils.py", line 22, in <module>
        true_bit = bool_t(1)
    TypeError: 'IntType' object is not callable
    >>> 
    

    Has anyone a clue what the problem could be? I am grateful for any hints or tips. Thank you!!!!!

  • Sreehari R
    Sreehari R over 6 years
    I tried this but I get the following: error:root@raspberrypi:/home/pi# sudo pip3 install llvmite==0.15.0 Downloading/unpacking llvmite==0.15.0 Could not find any downloads that satisfy the requirement llvmite==0.15.0 Cleaning up... No distributions at all found for llvmite==0.15.0 Storing debug log for failure in /root/.pip/pip.log
  • Matthew Berryman
    Matthew Berryman over 6 years
    Looks like it's simply a typo, it should be llvmlite==0.15.0 but you've written llvmite==0.15.0
  • Sreehari R
    Sreehari R over 6 years
    @MatthewBerryman I'm trying to do this on my Rpi3 and I get the following error: Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-DApH0j/llvmlite/setup.py';‌​f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-UCWh1n-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-DApH0j/llvmlite/
  • Matthew Berryman
    Matthew Berryman over 6 years
    @SreehariR very hard to say without the error log from pip. Can you paste here (or if it won't fit, paste elsewhere and link)? Just checking you've run the command sudo apt install libblas-dev llvm python3-pip python3-scipy to install llvm? You may need to add llvm-dev to that list of packages.
  • Sreehari R
    Sreehari R over 6 years
    Ok I'll attach a google docs link, also its worth noting that I'm not using a virtualenv (I don't know if that changes things)
  • Sreehari R
    Sreehari R over 6 years
    Here is the docs link: docs.google.com/document/d/…
  • Matthew Berryman
    Matthew Berryman over 6 years
    @SreehariR a couple of things: (1) if you're not using virtualenv then you need to run sudo pip3 install ... to install system-wide (for python3) or if you want to use python2 then sudo pip install ... for each of the packages. However (2) that unhelpful error message you're seeing is actually caused when pip can't connect to the server to download the packages (pip3 is a little bit more helpful in that it tells you what server is down). I have reported the server problem to the person who maintains it and will let you know when it's back up.
  • Sreehari R
    Sreehari R over 6 years
    @MatthewBerryman Thank you for filing the issue and notifying me! I really appreciate it.
  • Matthew Berryman
    Matthew Berryman over 6 years
    @SreehariR I haven't heard back from the person who runs the server but tested just then and the pip install worked again for me, so it seems it's fixed.
  • Sreehari R
    Sreehari R over 6 years
    @MatthewBerryman I was able to run the first line. However when trying to run the command sudo pip install numba==0.30.1 I got the same error. I updated the docs link with the error message: docs.google.com/document/d/…
  • Matthew Berryman
    Matthew Berryman over 6 years