Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install SciPy on Apple Silicon (ARM / M1)

I have successfully installed python 3.9.1 with Numpy and Matplotlib on a new Mac mini with Apple Silicon. However, I cannot install SciPy : I get compilation errors when using

python3 -m pip install scipy

I also tried installing everything from brew, and import scipy works, but using it gives a seg fault. I have installed ARM versions of lapack and openblas, but this does not fix the problem.

Has anyone succeeded? (I am interested in running it natively, not through Rosetta).

like image 808
David Sénéchal Avatar asked Jan 16 '21 01:01

David Sénéchal


People also ask

How do I manually install SciPy?

We can install the SciPy library by using pip command; run the following command in the terminal: pip install scipy.


Video Answer


3 Answers

It's possible to install on regular arm64 brew python, you need to compile it yourself.

If numpy is already installed (from wheels) you'll need to uninstall it:

pip3 uninstall -y numpy pythran

I had to compile numpy, which requires cython and pybind11:

pip3 install cython pybind11

Then numpy can be compiled:

pip3 install --no-binary :all: --no-use-pep517 numpy

Scipy needs pythran (this should happen after installing numpy):

pip3 install pythran

Then we need to compile scipy itself, it depends on fortran and BLAS/LACK:

brew install openblas gfortran

Tell scipy where it can find this library:

export OPENBLAS=/opt/homebrew/opt/openblas/lib/

Then finally compilescipy:

pip3 install --no-binary :all: --no-use-pep517 scipy
like image 140
Marijn Avatar answered Oct 28 '22 19:10

Marijn


This one worked for me after wasting hours:

pip install --pre -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy
like image 63
Jumshud Avatar answered Oct 28 '22 20:10

Jumshud


This solution worked on my M1 machine with pyenv:

brew install openblas
OPENBLAS="$(brew --prefix openblas)" pip install numpy scipy
like image 44
dwolfeu Avatar answered Oct 28 '22 21:10

dwolfeu