在Macbook M1上使用Python 3.7安装numpy。

4

我正在进行一个需要使用Python 3.7的项目。我尝试通过运行以下命令来解决我的setup.pyrequirements.txt之间的不匹配:

pip-compile --output-file=requirements.txt setup.py 

但我遇到了这个错误

compile options: '-DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=3 -DHAVE_CBLAS -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Inumpy/core/include -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/Users/me/.pyenv/versions/3.7.13/envs/queue-volume-drivers-3.7.13/include -I/Users/me/.pyenv/versions/3.7.13/include/python3.7m -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/npymath -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/npymath -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/npymath -c'
              extra options: '-faltivec -I/System/Library/Frameworks/vecLib.framework/Headers'
              clang: numpy/core/src/multiarray/alloc.c
              clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
              clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
              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/openssl@3/include -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=3 -DHAVE_CBLAS -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Inumpy/core/include -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/Users/me/.pyenv/versions/3.7.13/envs/queue-volume-drivers-3.7.13/include -I/Users/me/.pyenv/versions/3.7.13/include/python3.7m -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/npymath -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/npymath -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/private -Ibuild/src.macosx-12.6-arm64-3.7/numpy/core/src/npymath -c numpy/core/src/multiarray/alloc.c -o build/temp.macosx-12.6-arm64-3.7/numpy/core/src/multiarray/alloc.o -MMD -MF build/temp.macosx-12.6-arm64-3.7/numpy/core/src/multiarray/alloc.o.d -faltivec -I/System/Library/Frameworks/vecLib.framework/Headers" failed with exit status 1
              [end of output]
        
          note: This error originates from a subprocess, and is likely not a problem with pip.
        error: legacy-install-failure
        
        × Encountered error while trying to install package.
        ╰─> numpy
1个回答

3

我也遇到了这个错误。发生这种情况是因为pip-compile不能/不会使用预编译的numpy wheel(这是pip install通常做的),并且尝试在本地编译它。看起来,在Python 3.7和3.8上(我已经测试过)numpy和macOS内置的BLAS(基本线性代数子程序)库彼此不兼容,因此编译失败。

为了解决这个faltivec问题,我们需要链接一个不同的BLAS库。OpenBLAS很适合这个任务。

因此解决方案是:

  1. 使用brew install openblas安装OpenBLAS
  2. 像这样运行pip-compileOPENBLAS=$(brew --prefix openblas) pip-compile --output-file=requirements.txt setup.py

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接