简体   繁体   English

在树莓派 3 上运行 librosa 和 numba

[英]running librosa & numba on raspberry pi 3

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.我正在尝试在我的 raspberry pi 3 上运行 librosa。在通过互联网搜索数小时后,我终于能够安装它,但是当我尝试导入它时仍然会引发错误。 First, I had problems to install the dependency llvmlite .首先,我在安装依赖项llvmlite遇到了问题。 I finally installed it with the following code: conda install -c numba llvmlite .我最终使用以下代码安装了它: conda install -c numba llvmlite I use python 3.4 build with miniconda.我使用带有 miniconda 的 python 3.4 构建。

After llvmlite was installed I was able to install librosa with pip (not possible with conda)安装 llvmlite 后,我可以使用pip安装 librosa(无法使用 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.显然 librosa 已安装。

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:尝试导入 librosa 会引发以下错误:

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:尝试导入 numba 会引发以下错误:

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!!!!!谢谢!!!!

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.在撰写本文时,最新的 Raspbian 版本具有 llvm-3.8,因此根据此 github 评论,您需要使用 numba v0.30.1 安装 llvmlite v0.15.0。 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.如果您在不同的 llvm 上,那么您将需要探索 llvmlite 和 numba 的版本与该版本的 llvm 一起使用。 Here are the commands that got me set up to get a successful import librosa :以下是让我设置成功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.注意我正在使用 virtualenv 并从系统包中拖入 scipy 和 numpy,否则很难获得正确的 fortran 和 c 依赖项,而且这些依赖项需要很长时间才能在 RPi 上进行编译。 If you want to install system-wide then drop the 2nd and 3rd line and put sudo in front of the pip commands.如果要在系统范围内安装,请删除第 2 行和第 3 行并将sudo放在pip命令前面。 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我还在这个requirements.txt文件中冻结了我的需求,所以如果你下载它,那么你可以运行一个命令pip install -r requirements.txt

sudo pip install librosa==0.4.2 worked for me. sudo pip install librosa==0.4.2对我sudo pip install librosa==0.4.2 There was warning yet works fine on Raspberry pi3 (OS:raspbian-jessie)有警告但在 Raspberry pi3 上工作正常(操作系统:raspbian-jessie)

Thanks @MatthewBerryman, you got me over the hump!谢谢@MatthewBerryman,你让我克服了困难! 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).在最新的 Raspian 版本(stretch)上,在尝试在 Raspian jessie(我的 RPi3 附带的)上安装 librosa 经历了几个小时的挫折之后,我成功地完成了以下操作。 Having said this, the following procedure may also work with jessie.话虽如此,以下过程也可能适用于 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:安装 Python 科学堆栈:

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

(Also seems to install matplotlib, scipy) (好像还安装了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.然后,安装低级虚拟机 LLVM(根据 @MatthewBerryman,我使用了 llvm 3.8 和 llvmlite 0.15.0,而不是我找不到软件包的最新组合。)安装 llvm-3.8 后,一个符号链接需要在安装 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. Numba 是 0.32.0,因为如果它是最新的(0.36),它不会因为 llvm 不匹配而导入,如果它是较低版本,librosa 安装会将其升级到最新版本。

Finally, install librosa:最后,安装 librosa:

sudo pip3 install librosa

However, when trying to import librosa, it still throws and error, namely但是,在尝试导入 librosa 时,它仍然抛出并出错,即

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:总结一下,这个过程安装librosa,尝试这个没有错误:

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

https://raspberrypi.stackexchange.com/questions/111697/unable-to-pip-install-librosa-in-raspberry-pi-3-model-b-raspbian-stretch https://raspberrypi.stackexchange.com/questions/111697/unable-to-pip-install-librosa-in-raspberry-pi-3-model-b-raspbian-stretch

Anyone can refer this link , I got a successful install in RPi 3 B+ with Raspbian Buster OS任何人都可以参考此链接,我使用 Raspbian Buster OS 在 RPi 3 B+ 中成功安装

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.然后安装 virtualenv 并创建一个新的 virtualenv。

Activate the virtualenv using python3.使用 python3 激活 virtualenv。

sudo apt-get install llvm

You should get llvm 7.0.x你应该得到 llvm 7.0.x

Then install a compatible llvmlite - this works for 7.0.然后安装兼容的 llvmlite - 这适用于 7.0。 Get the path by typing which llvm-config In my case it was /usr/bin/llvm-config通过键入which llvm-config获取路径在我的情况下它是 /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如果在尝试导入 librosa 后由于 numpy 出现错误,请更新依赖项

sudo apt-get install libatlas-base-dev

Credits to this tutorial教程的积分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM