LoginSignup
5
3

More than 5 years have passed since last update.

Raspbian Stretch with Desktopにlibrosaをインストールする

Posted at

イントロダクション

librosaは音楽やオーディオ解析用のPythonパッケージです。機械学習で入力として与えるデータのための特徴抽出に便利な機能が多数用意されています。IAMAS Advent Calendar 2017で連載(?)している「機械学習とRaspberry Piを用いてレーザー加工機の動作状態を判定する」でも様々な信号処理やファイル読み込みで活用しています。

Raspberry Piで使おうとする人は希かもしれませんが、インストール時に引っかかったところがありましたので備忘録として残しておきたいと思います。

課題

librosaのウェブサイトではインストール方法としてpip install librosaを紹介しています。しかしながら、Raspbian Stretch with Desktop (November 2017)で実行すると以下のようにエラーが発生します。

$ sudo pip3 install librosa
Collecting librosa
...
Collecting numba>=0.32 (from resampy>=0.1.2->librosa)
  Downloading https://www.piwheels.hostedpi.com/simple/numba/numba-0.35.0-cp35-cp35m-linux_armv7l.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 31kB/s 
Collecting llvmlite (from numba>=0.32->resampy>=0.1.2->librosa)
  Downloading llvmlite-0.20.0.tar.gz (96kB)
    100% |████████████████████████████████| 102kB 299kB/s 
Building wheels for collected packages: llvmlite
  Running setup.py bdist_wheel for llvmlite ... error
...
  FileNotFoundError: [Errno 2] No such file or directory: 'llvm-config'

発生しているエラーはFileNotFoundError: [Errno 2] No such file or directory: 'llvm-config'です。librosaが依存しているresampyが依存しているnumbaが依存しているLLVMをPythonから扱うためのライブラリllvmliteをビルドするところで発生しています。

解決策

resampyのreleasesを確認してみると、0.2.0からCythonで実装していたものをNumbaによる実装に置き換えたようです。

0.2.0rc0

Release candidate for 0.2.0.

This version replaces the Cython core with a Numba implementation, and should fix compiler-related installation issues.

0.2.0の一つ前のバージョンである0.1.5であれば、LLVMをインストールする必要はなさそうです。インストールしようとしたlibrosaの0.5.1のsetup.pyを確認すると、要求されているresampyバージョンは0.1.2以上ですので、0.1.5であれば大丈夫そうです。

setup.py
setup(
    ...
    install_requires=[
        'audioread >= 2.0.0',
        'numpy >= 1.8.0',
        'scipy >= 0.13.0',
        'scikit-learn >= 0.14.0',
        'joblib >= 0.7.0',
        'decorator >= 3.0.0',
        'six >= 1.3',
        'resampy >= 0.1.2'

実際に、以下のようにresampyのバージョンを指定することにより、無事にlibrosaをインストールすることができました。

$ sudo pip3 install resampy==0.1.5 librosa
...
Installing collected packages: Cython, resampy, librosa
Successfully installed Cython-0.27.3 librosa-0.5.0 resampy-0.1.5

根本的な解決策

ひとまず0.5.1に関しては上記の方法でインストールできました。しかしながら、今後resampyの0.2.0以上が指定された場合にはLLVMをインストールする必要が出てくるでしょう。

llvmliteのRelease Notesを確認すると、最新の0.20.0にはLLVMのバージョン5が必要になるようです。しかしながら、2017年12月6日の時点でRaspbian用に用意されているLLVMは3.9までのようです。

$ apt-cache search llvm
llvm - Low-Level Virtual Machine (LLVM)
...
llvm-3.9 - Modular compiler and toolchain technologies
llvm-3.9-dev - Modular compiler and toolchain technologies, libraries and headers
llvm-3.9-doc - Modular compiler and toolchain technologies, documentation
llvm-3.9-examples - Modular compiler and toolchain technologies, examples
llvm-3.9-runtime - Modular compiler and toolchain technologies, IR interpreter
llvm-3.9-tools - Modular compiler and toolchain technologies, tools
llvm-dev - Low-Level Virtual Machine (LLVM), libraries and headers
llvm-runtime - Low-Level Virtual Machine (LLVM), bytecode interpreter

同じくllvmliteのRelease Notesによれば、3.9が対応しているのは0.16.0までですので、最新版をインストールしたいのであれば別の方法で用意する必要があります。

v0.16.0
API changes:

Switched from LLVM 3.8 to 3.9

いずれビルド済みのパッケージが用意されることに期待しつつ、どうしても必要になったときのためにLLVMのビルド方法についても調べておきたいと思います。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3