我确实成功地安装了llvmlite,谢谢这帖子。然而,pip install numba
一直在失败。
那么,有没有办法在Mac M1上安装numba呢?
(我认为有关的错误线如下:
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
)
发布于 2022-09-08 15:13:50
Python可以作为轮子(意为已构建的版本,可以随时使用)或sdists (源代码分发,只提供源代码和如何构建它的说明)分发。
sdists版本通常很难在M1体系结构上构建。
虽然在最新的numba版本(0.56.2
)上目前还没有Mac 0.56.2
的轮子,但是已经为版本0.55.2
二度创建了一个轮子,因此您可以使用:
pip install numba==0.55.2
发布于 2022-09-09 14:50:20
微型锻造是安装M1兼容库的好方法。
conda install numba
将自动安装Numba0.55.2和所有依赖项。
conda instal -c numba numba==0.56.2
将强制从numba通道直接安装0.56.2 (这在M1 Pro和Python3.9.13上适用)。
发布于 2022-09-15 18:42:14
numba-0.56.2
为macos的arm64版本提供了Python轮子,支持Python3.9.x和3.10.x,就像您在PyPI文件页上看到的那样。
由于您使用的是macos蒙特雷,所以您应该能够使用系统提供的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
你可以看到安装工作如下:
❯ 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
你在评论中也这样说:
看看你的链接,我只找到了macosx_11__arm64的轮子。我以为Mac 11版是大苏尔,我在蒙特利?
不需要构建支持特定操作系统版本的轮子,如果使用pip
,debug --verbose
可以告诉您哪些标记与它兼容。
您可以在这里看到,蒙特雷提供的系统提供的Python3.9与具有版本/平台/体系结构字符串用于多个版本的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...
如果您在使用任何版本的Python安装Numba时遇到问题,请检查pip3 debug --verbose
并查看是否有与车轮名称匹配的字符串。
https://stackoverflow.com/questions/73646130
复制相似问题