如何在AppleSilicon(ARM/M1)上安装SciPy
我已经在带有 Apple Silicon 的新 Mac mini 上成功安装了带有 Numpy 和 Matplotlib 的 python 3.9.1。但是,我无法安装 SciPy:使用时出现编译错误
python3 -m pip install scipy
我还尝试从 brew 安装所有内容,并且“import scipy”有效,但使用它会导致段错误。我已经安装了 lapack 和 openblas 的 ARM 版本,但这并不能解决问题。
有人成功了吗?(我有兴趣在本地运行它,而不是通过 Rosetta)。
回答
可以安装在普通的arm64 brew python 上,需要自己编译。
首先我必须编译numpy,这需要cython和pybind11:
pip3 install cython pybind11
然后numpy可以编译:
pip3 install --no-binary :all: --no-use-pep517 numpy
然后我们需要自己编译scipy,它依赖于fortran和BLAS/LACK:
brew install openblas gfortran
告诉scipy它在哪里可以找到这个库:
export OPENBLAS=/opt/homebrew/opt/openblas/lib/
然后最后编译scipy:
pip3 install --no-binary :all: --no-use-pep517 scipy
- Unfortunately the `SciPy` compilation failed with `error: Command "ar rcs build/temp.macosx-10.14.6-arm64-3.8/libsuperlu_src.a build/temp.macosx-10.14.6-arm64-3.8/scipy/sparse/linalg/dsolve/SuperLU/SRC/dlaqgs.o [………]" failed with exit status 1` 🙁
- 我需要 pip install pythran
回答
此解决方案适用于我的 M1 机器pyenv:
brew install openblas
OPENBLAS="$(brew --prefix openblas)" pip install numpy scipy
- 这对我有用。我还可以使用相同的方法安装 `scikit-learn`:`OPENBLAS="$(brew --prefix openblas)" pip install numpy scikit-learn`
回答
您可以从https://github.com/conda-forge/miniforge#miniforge3安装 miniforge
,然后安装这些软件包,
conda install numpy scipy matplotlib
- You can also install miniforge using brew: `brew install --cask miniforge`