0

I did manage to install llvmlite thanks this post. However, pip install numba keeps on failing.

So, is there a way to install numba on a Mac M1?

(I think the relevant error lines are the following:

numba/core/typeconv/typeconv.cpp:30:19: error: expected expression
    bin.push_back({key, val});
                  ^
1 error generated.
numba/_dispatcher.cpp:1104:37: warning: offset of on non-POD type 'Dispatcher' [-Winvalid-offsetof]
    {(char*)"_can_compile", T_BOOL, offsetof(Dispatcher, can_compile), 0, NULL },
                                    ^                    ~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/stddef.h:104:24: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^                     ~
1 warning generated.
error: Command "clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/openblas/include -I/Users/kotchwane/.pyenv/versions/3.10.6/lib/python3.10/site-packages/numpy/core/include -I/Users/kotchwane/.pyenv/versions/3.10.6/include/python3.10 -c numba/core/typeconv/typeconv.cpp -o build/temp.macosx-10.16-arm64-3.10/numba/core/typeconv/typeconv.o" failed with exit status 1

)

xxx
  • 1,153
  • 1
  • 11
  • 23
kotchwane
  • 2,082
  • 1
  • 19
  • 24
  • What version of MacOS and Python are you using? They have `numba` wheels built for Python 3.8/3.9/3.10 for M1 macs. – wkl Sep 08 '22 at 15:19
  • Interesting! I have MacOS 12 and Python 3.9.13. How do I find the available `numba` wheels for each Python version ? – kotchwane Sep 08 '22 at 15:30
  • 1
    They're listed on PyPI for each package, like here's numba's: https://pypi.org/project/numba/#files. I've also installed numba without needing to compile using Python 3.9 and 3.10 (M1 Silicon, macos 12.x). – wkl Sep 08 '22 at 15:32
  • Looking at your link, I only find wheels for macosx_11_0_arm64. I thought Mac version 11 was Big Sur, and I am on Monterey? – kotchwane Sep 12 '22 at 07:38

3 Answers3

2

Python packages can be distributed either as wheels (meaning, a built version, ready to be used) or as sdists (source distribution, providing only the source code and the instructions on how to build it).¹

The sdists versions are generally hard to build on M1 architecture.

Although a wheel for Mac M1 is not available currently on the latest numba version (0.56.2), one has been created for version 0.55.2², so you can use:

pip install numba==0.55.2 
kotchwane
  • 2,082
  • 1
  • 19
  • 24
0

Miniforge is a great way to have install M1 compatible libraries.

conda install numba will automatically install numba 0.55.2 and all the dependencies.
conda instal -c numba numba==0.56.2 will force install 0.56.2 directly from the numba channel (which works for me on M1 Pro and Python 3.9.13).

Louis-Amand
  • 101
  • 7
0

numba-0.56.2 has Python wheels for arm64 versions of macos, supporting Python versions 3.9.x and 3.10.x, as you can see on the numba PyPI files page.

Since you're on macos Monterey, you should be able to install using the system-provided Python:

# Using venv
❯ /usr/bin/python3 -V
Python 3.9.6
❯ /usr/bin/python3 -m venv .sysvenv
❯ source .sysvenv/bin/activate
❯ pip install numba
Collecting numba
  Downloading numba-0.56.2-cp39-cp39-macosx_11_0_arm64.whl (2.4 MB)
     |████████████████████████████████| 2.4 MB 6.1 MB/s
Collecting numpy<1.24,>=1.18
  Downloading numpy-1.23.3-cp39-cp39-macosx_11_0_arm64.whl (13.4 MB)
     |████████████████████████████████| 13.4 MB 10.2 MB/s
Requirement already satisfied: setuptools<60 in ./.sysvenv/lib/python3.9/site-packages (from numba) (58.0.4)
Collecting llvmlite<0.40,>=0.39.0dev0
  Downloading llvmlite-0.39.1-cp39-cp39-macosx_11_0_arm64.whl (23.1 MB)
     |████████████████████████████████| 23.1 MB 17.3 MB/s
Installing collected packages: numpy, llvmlite, numba
Successfully installed llvmlite-0.39.1 numba-0.56.2 numpy-1.23.3

And you can see the installation works as-is:

❯ python
Python 3.9.6 (default, Aug  5 2022, 15:21:02)
[Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numba
>>> print(numba.__version__)
0.56.2
>>>
>>> import random
>>>
>>> @njit
... def monte_carlo_pi(nsamples):
...     acc = 0
...     for i in range(nsamples):
...         x = random.random()
...         y = random.random()
...         if (x ** 2 + y ** 2) < 1.0:
...             acc += 1
...     return 4.0 * acc / nsamples
...
>>> monte_carlo_pi(10)
3.2

You also said this in the comments:

Looking at your link, I only find wheels for macosx_11_0_arm64. I thought Mac version 11 was Big Sur, and I am on Monterey?

Wheels don't have to be built supporting the specific OS version, and pip can tell you what tags are compatible with it, if you use debug --verbose.

You can see here that the system-provided Python 3.9 in Monterey is compatible with wheels that have the version/platform/architecture strings for multiple versions of macos:

❯ /usr/bin/python3 -m pip debug --verbose | grep arm64
  cp39-cp39-macosx_12_0_arm64
  cp39-cp39-macosx_11_0_arm64
  cp39-abi3-macosx_12_0_arm64
  cp39-abi3-macosx_11_0_arm64
# etc...

If you are having troubles installing Numba with whatever version of Python you're using, check pip3 debug --verbose and see if you get strings that match the wheel names.

wkl
  • 77,184
  • 16
  • 165
  • 176