Install numba to mac

Posted: , Modified:   python numba mac
Copyright certificate by blockai


numba provides an easy optimization for python codes but pip doesn’t work to install numba. This entry explains installation and import way of numba.


numba requires llvm and enum34, and the required version of llvm isn’t the newest version 3.8.x but version 3.7.x. To install such version, you need to tap homebrew/versions and set environ variable LLVM_CONFIG. The following steps do that.

$ 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

Import numba

We should prepare import even if our source code will run without numba, and we replace no-op decorate if numba cannot be imported. The following source code do that:

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

If your code has other decorators than @jit, you need to define those decorators, and in this case, you need to give types as texts not objects.