LoginSignup
5
9

More than 5 years have passed since last update.

Mac に numba をインストール

Last updated at Posted at 2016-07-29

概要

English
お手軽に python コードを高速化するために,numba を導入してみた.
しかし,pip だけではインストールできなかったので,備忘録としてインストール手順を記録しておく.

インストール

llvmenum34 が別途必要らしい.
特に,llvm は最新の 3.8.x ではなく 3.7.x が要るようなので,
homebrew/versions を tap してインストールする.
また,環境変数 LLVM_CONFIG の設定を忘れないようにする.

brew tap homebrew/versions
brew install homebrew/versions/llvm37
export LLVM_CONFIG=/usr/local/Cellar/llvm37/3.7.1/bin/llvm-config-3.7

pip install enum34
pip install numba

インポート

numba がインストールされていない環境でも動くように,
インポートできなかった場合は何もしないデコレータに差し替えておく.

try:
    from numba import jit
except ImportError:
    def jit(*args, **_kwargs):
        if len(args) > 0 and hasattr(args[0], "__call__"):
            return args[0]
        else:
            def _(func):
                return func
            return _

@jit 以外も使う場合は同様のものをそれぞれ定義する.
また,この場合型指定はオブジェクトではなく文字列で渡す必要がある.

その他

文献はこの辺り?

5
9
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
9