4

Respected people,

Attempt 1: when I run the command,

pip3 install librosa 

I am stuck here,

Running setup.py bdist_wheel for scipy ... \

It was taking more then 2 hours but it was still continuing the same, finally it was built , but i get a lot of error after that

Attempt 2:

I saved these in requirements.txt and ran the command

pip install -r requirements.txt

>>> import librosa
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.5/site-packages/librosa/__init__.py", line 12, in <module>
    from . import core
  File "/home/pi/.local/lib/python3.5/site-packages/librosa/core/__init__.py", line 109, in <module>
    from .audio import *  # pylint: disable=wildcard-import
  File "/home/pi/.local/lib/python3.5/site-packages/librosa/core/audio.py", line 12, in <module>
    import resampy
  File "/home/pi/.local/lib/python3.5/site-packages/resampy/__init__.py", line 7, in <module>
    from .core import *
  File "/home/pi/.local/lib/python3.5/site-packages/resampy/core.py", line 9, in <module>
    from .interpn import resample_f
  File "/home/pi/.local/lib/python3.5/site-packages/resampy/interpn.py", line 4, in <module>
    import numba
  File "/home/pi/.local/lib/python3.5/site-packages/numba/__init__.py", line 23, in <module>
    from .decorators import autojit, cfunc, generated_jit, jit, njit
  File "/home/pi/.local/lib/python3.5/site-packages/numba/decorators.py", line 11, in <module>
    from .targets import registry
  File "/home/pi/.local/lib/python3.5/site-packages/numba/targets/registry.py", line 6, in <module>
    from . import cpu
  File "/home/pi/.local/lib/python3.5/site-packages/numba/targets/cpu.py", line 10, in <module>
    from .base import BaseContext, PYOBJECT
  File "/home/pi/.local/lib/python3.5/site-packages/numba/targets/base.py", line 17, in <module>
    from numba import _dynfunc, _helperlib
ImportError: numpy.core.multiarray failed to import

How can I solve this ? please help!

audioread==2.1.5 cryptography==1.7.1 decorator==4.0.11 idna==2.2 joblib==0.11 keyring==10.1 keyrings.alt==1.3 librosa==0.5.1 llvmlite==0.15.0 numba==0.30.1 numpy==1.12.1 pyasn1==0.1.9 pycrypto==2.6.1 pygobject==3.22.0 python-apt==1.1.0b5 pyxdg==0.25 resampy==0.2.0 scikit-learn==0.19.0 scipy==0.18.1 SecretStorage==2.3.1 six==1.10.0 virtualenv==15.1.0

In Raspbian buster I got the following!,This should not be fatal!!

Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import librosa
/home/pi/.local/lib/python3.7/site-packages/librosa/util/decorators.py:9: NumbaDeprecationWarning: An import was requested from a module that has moved location.
Import requested from: 'numba.decorators', please update to use 'numba.core.decorators' or pin to Numba version 0.48.0. This alias will not be present in Numba version 0.50.0.
  from numba.decorators import jit as optional_jit
/home/pi/.local/lib/python3.7/site-packages/librosa/util/decorators.py:9: NumbaDeprecationWarning: An import was requested from a module that has moved location.
Import of 'jit' requested from: 'numba.decorators', please update to use 'numba.core.decorators' or pin to Numba version 0.48.0. This alias will not be present in Numba version 0.50.0.
  from numba.decorators import jit as optional_jit
13
  • Hi Sundar - I see you're new here, welcome :-) Have you considered the advice the error message gives? ("Consider using the --user option or check the permissions.") And if so what did you try? Rather than trying to butter people up ("Respected people") it'll generally be more effective if you show some initiative / willingness to rule out the sensible things first (even if that's more work for you than just asking others) as that makes people more motivated to help you (since you won't come across as lazy - not that I'm saying you are...)
    – Neil
    Apr 24, 2020 at 22:55
  • Yeah i tried that out too.. but still I have errors ! Apr 25, 2020 at 19:37
  • @Neil Do you have any idea why do I get the above error? thanks! Apr 26, 2020 at 5:50
  • What did you find out about the file permissions? I see you've changed the error message with no indication of what you changed in your approach (this reduces the value of this question for others who run into your initial problem). You also still don't include sufficient detail about your setup to help someone to help you
    – Neil
    Apr 26, 2020 at 12:59
  • As well as the points above, how about including the output of pip list? My guess is that it'll relate to the version of numpy you've got (or possibly other packages)
    – Neil
    Apr 26, 2020 at 21:24

1 Answer 1

4

The issue here is with numba, as you'll see with the last two lines of the trace:

  File "/home/pi/.local/lib/python3.5/site-packages/numba/targets/base.py", line 17, in <module>
    from numba import _dynfunc, _helperlib
ImportError: numpy.core.multiarray failed to import

I had this issue myself when installing librosa recently on a Raspberry Pi.


Despite the numba issue, let's start with a few basics first as you ultimately want to install librosa:

  • this will be easiest to manage if you do it in a virtual environment
    • I'll leave that to you and Google
    • main advantage is any mistakes from previous steps are less likely to cause you grief!
    • if you don't go for a virtual env then be sure to clear out all the related python packages you pip installed so you've got a clean base
  • getting llvmlite installed
  • installing a suitable version of numpy for numba
  • installing the rest (ie librosa and all the remaining dependencies)

Note: I suggest you install a newer version of librosa than the one in your requirements.txt (or you'll run into issues where the official recommendation is update to 0.6!)

llvmlite

The python package llvmlite is needed by numba, which in turn is needed by librosa.

The llvmlite package depends on the OS package LLVM (it's a compiler/toolchain) and it requires a specific version of LLVM (more info here). Fortunately we don't need to compile it from scratch as currently the version in Raspbian is version 7.0 so you can install it by running the following:

sudo apt install llvm

(just be sure to confirm that the version installing is 7)

Then find out where llvm-config was installed with:

which llvm-config

And paste that result into this LLVM_CONFIG=/path/to/llvm-config pip3 install llvmlite for me results in:

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

Leave that to install.

At some points the output will shown mention of failures, but then runs setup.py and ends with these lines:

Failed to build llvmlite

Installing collected packages: llvmlite

Running setup.py install for llvmlite ... done

Successfully installed

llvmlite-0.32.0

You can double-check things worked to this point with:

python -m llvmlite.tests

which will run tests and reports "OK (skipped=3)".

numpy / numba

I found that numba would install but did not work (giving the error you observe) when I had numpy 1.15.x installed. Also to get it to install from piwheels you need

sudo apt install libatlas3-base

Then run this:

pip install numpy==1.16.1 numba

The output indicating it completed should be:

Successfully installed numba-0.49.0 numpy-1.16.1

When that completes, in python try import numba - it should succeed (ie show no error, just the next prompt) but if not then there's no point in proceeding until the issues at this point are resolved.

Installing the rest

From here on you should be okay just installing librosa. This is the point where I suggest 0.6.2 (or newer if reading this later).

pip install librosa==0.6.2

You will see the output pull in various files from PiWheels / PyPI. It should end with a success message:

Successfully installed audioread-2.1.8 decorator-4.4.2 joblib-0.14.1 librosa-0.5.1 resampy-0.2.2 scikit-learn-0.22.2.post1 scipy-1.4.1 six-1.14.0

You can now see if it imports in Python. Note: you'll likely see a Deprecation Warning message but it shouldn't be fatal.

Also depending on what you want to actually do with librosa you may run into issues with the backend etc (eg if you test it with the first tutorial: https://librosa.github.io/librosa/tutorial.html#quickstart) That's beyond the scope of this answer but in that case, you may want to install ffmpeg (see https://github.com/librosa/librosa#audioread-and-mp3-support / sudo apt install ffmpeg )

From the look of your requirements.txt you may have some additional packages you want to install but if you're just after librosa then you should be done.


Hope that helps! I just re-tested it on a 100% freshly installed image of Raspbian Buster Lite (version: Feb 2020).

Let me know in the comments if you run into further problems. And don't forget to accept the answer if it works.

8
  • After following this I got some warnings which is posted above May 6, 2020 at 4:03
  • I think as mentioned warrnings shouldn't be fatal! I have to thank you so much as this is the best resource available to install librosa in RPi by far!!! May 6, 2020 at 4:32
  • Yes, it looks like that's a warning regarding future compatibility. Glad you got it working in the end :-)
    – Neil
    May 7, 2020 at 7:30
  • 2
    Confirming this still works for the newest Librosa 0.8.0! Fantastic instructions. By far the simplest! Now to get LLVM 8 or higher to work..!
    – Austin
    Oct 7, 2020 at 18:55
  • I had to install llvm-9 to get this working ("RuntimeError: Building llvmlite requires LLVM 10.0.x or 9.0.x, got '7.0.1'."). Nov 2, 2020 at 20:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.