62

I am using MacBook m1 which is running Big Sur 11.1 ,and I have installed Xcode-commandline-tools version 12.3 and it has installed python3.8.5 and pip3 .python3 and pip are native apps,that is they run in ARM

pip3 version 20.3.3

python3 version 3.8.5

setuptools version 51.0.0

wheel version 0.36.2

when I type python3 -m pip install numpy

The output is :

Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Using cached numpy-1.19.4.zip (7.3 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517): started
sandeep@Sandeeps-Air ~ % cat a
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Using cached numpy-1.19.4.zip (7.3 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517): started
  Building wheel for numpy (PEP 517): finished with status 'error'
Failed to build numpy

and with a very large list of errors

Is numpy still not supported in M1 or am I doing it wrong ?

14 Answers 14

66

I had exactly the same issue with my brand new Mac Mini. After spending an afternoon reading this issue on github, I finally succeeded. However, it only seems to work with v1.20.0rc2 or above...

Long story short, these were the steps I've taken to get it working:

pip3 install Cython
git clone https://github.com/numpy/numpy.git 
cd numpy
pip3 install . --no-binary :all: --no-use-pep517

After that, I could cd into my virtualenv and import numpy:

>>> import numpy as np
>>> np.__version__
'1.21.0.dev0+402.gc4ae3ce64'
>>> 

Next up: pandas.

UPDATE: After some more searching, I found this interesting article, which states that you can easily start Terminal in Rosatta mode. That also solved the issues.

However, I am working with a headless Mac Mini, so I still have to find out whether that solution also is feasable in that particular setup.

UPDATE 2

I now have pandas working as well, thanks to this answer on SO.

4
  • 1
    I had the same issue though a variant of it. I was installing numpy inside docker (preview for M1). The steps here were helpful to point me in a direction. I needed a specific version of numpy installed so after cloning I checkout out the version I needed git checkout v1.xx.x and went ahead to install.
    – gmajivu
    Feb 10, 2021 at 9:19
  • 3
    slight variant: skipping the git download, I just directly did pip3 install --no-binary :all: --no-use-pep517 numpy and it works for me
    – CrepeGoat
    May 13, 2021 at 18:49
  • 1
    For Python 3.9.5 & pip 21.1.2, git-download method didn't work but the the skipping method that @CrepeGoat suggests worked fine! Great. Jun 7, 2021 at 0:16
  • Thanks!!! The one-liner is pip install git+github.com/numpy/numpy.git --no-binary :all: --no-use-pep517 Jun 11, 2021 at 19:00
19

Yes, numpy still seems to be not supported in stable, but if you are ready to work with unstable version try this command:

pip3 install numpy --compile --pre

This will recompile all the necessary code from unstable branch.

Worked for me.

7
  • 4
    This got me closer to anything else I've tried, but I still ended up with ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly. Aargh! Dec 29, 2020 at 21:46
  • Maybe --no-use-pep517 does the trick? python.org/dev/peps/pep-0517 Jan 3, 2021 at 1:24
  • The --no-use-pep517 option didn't work for me and I got the same result as John Laundun.
    – JasonD
    Jan 19, 2021 at 19:24
  • 2
    It worked for me. I think the issue is that you should use the default xcode cli python. The version at this time is 3.8
    – Ateik
    Jan 26, 2021 at 16:51
  • This isn't working for me! It says the same thing whatever I do! ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly. I'm using Python v3.9, and nothing's working!
    – user13774796
    Apr 28, 2021 at 5:51
12

Since NumPy 1.21.0, it has released universal2 wheels for Python 3.8 and Python 3.9 on Mac. It becomes installable on Mac M1.

I have tested it on my M1 with Python 3.9.2, macOS Big Sur (11.5.1), and pip 21.1.3. Just use pip/pip3 to install it.

release note: https://github.com/numpy/numpy/releases/tag/v1.21.0

2
  • 3
    My M1 came with Python 3.8.9 installed and it failed to build numpy. Installing Python 3.9.10 via Homebrew fixed it.
    – Max
    Jan 26, 2022 at 22:44
  • It failed for me on the first time. I tried it again and it downloaded numpy instead of compiling it and it succeeded. Also works with pyenv on 3.8 and 3.9. pyenv with 3.12 still fails.
    – blacktide
    Dec 8, 2022 at 0:51
5

Note that the only reliable build environment for the full data-science suite for python at the moment (Feb 2021) on M1 ARM architecture is via miniforge.

e.g.

brew install --cask miniforge
conda init zsh
conda activate
conda install numpy scipy scikit-learn
1
  • 1
    Thanks this is the only thing that worked for me. I am using the VScode M1 insiders build and setting my interpreter to where miniforge is got all these working. Feb 11, 2021 at 3:05
5

What it worked for me was to run iTerm with the option "open using Rosetta" enabled and upgrade pip before installing numpy.

enter image description here

Instead of enabling this option you could also run the pip install and python selecting a different architecture with arch -x86_64. Example using a virtual environment:

$ python3 -m venv ~/myenv
$ source ~/myenv/bin/activate
(myenv)$ python3 -m pip install --upgrade pip
Collecting pip
  Using cached pip-21.0.1-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-21.0.1

(myenv)$ arch -x86_64 pip install numpy
Collecting numpy
  Using cached numpy-1.20.1-cp39-cp39-macosx_10_9_x86_64.whl (16.1 MB)
Installing collected packages: numpy
Successfully installed numpy-1.20.1

(myenv)$ arch -x86_64 python3
Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec  7 2020, 12:44:01)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.20.1'
1
  • 1
    Wanted to leave a comment that this was the only one which worked for M1. Specifically, setting Terminal to open in Rosetta, python3 -m pip install --upgrade pip, and lastly arch -x86_64 pip install numpy Jul 27, 2022 at 11:51
4

I was trying to install numpy without rosetta 2, but the solutions listed here failed for me. Brew saved the day. I installed it with

brew install numpy
1
3

Try this as I was able to install numpy using this method.

  1. brew install openblas (use the native homebrew instead of running it under Rosetta 2)
  2. OPENBLAS="$(brew --prefix openblas)" pip3 install numpy
2
  • this didn't work for me, fails with error ERROR: Command errored out with exit status 1: /opt/homebrew/opt/[email protected]/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/gz/p5bntj6n0tsbwm355mj3gb640000gn/T/tmpn9lk223d Check the logs for full command output.
    – varkashy
    Jan 19, 2021 at 14:02
  • 3
    Try using the command line tools installed python 3.8 instead of the brew installed python 3.9 Jan 20, 2021 at 15:08
2

First of all numpy support is not there for m1 arm based Macs using python 3.8 version. The method to workaround with this is to update your python version to 3.9. This is the latest version of python and can be a bit unstable. If you want to work with tensorflow then do not update to python 3.9 version as they don't support it and support will come up with version 2.5 (estimated). So, if you don't want to use tensorflow and want to use numpy by using pip install then go ahead install python3.9 and make it your default python interpreter.

I will recommend you to use Homebrew for installation of python 3.9 as it as easy as running a simple command.

2
  • could you add links to documentation that support what you are saying, please?
    – germanio
    Jan 20, 2021 at 15:48
  • Yes, so for my tensorflow response please follow this thread github.com/tensorflow/tensorflow/issues/44485 Checking the working of numpy was coincidence as python3.9 got installed for a package for me and then I tried installing numpy and it worked. You can surely look for other solutions for installing numpy without help of wheel by downloading and installing it from source(that should work but I am not sure).
    – Amritesh
    Jan 21, 2021 at 16:44
2

faced the same problem in monterey too.

upgrading pip version to 21.3.1 from 20.2.3 solved the issue.

source env/bin/activate
pip install -U pip
pip install numpy
0
1

A solution for pipenv users:

git clone https://github.com/numpy/numpy.git --recursive
cd numpy
pip3 install build
python3 -m build
cd dist
cp numpy-1.22.0.dev0+97.g4635fc852-cp39-cp39-macosx_11_0_arm64.whl ../../ # filename is current sample, next folder to your project directory

Add into Pipfile:

[packages]
numpy = { path = "numpy-1.22.0.dev0+97.g4635fc852-cp39-cp39-macosx_11_0_arm64.whl" }
pipenv install

then your numpy will be installed.

1

As mentioned in a previous answer, the installation went smooth when I opened the terminal using Rosetta.

However for anyone who is using Pycharm terminal, Do the following to get the terminal running using Rosetta.

  • Go to Preferences -> Tools -> Terminal
  • Update the script path to "env /usr/bin/arch -x86_64 /bin/zsh --login"

I tried a lot of other options but so far this was the simplest solution I found.

1
  • i highly recommend working hard enough to not use rosetts manually.... Jun 10 at 19:56
0

After trying a ton of suggested methods I finally found a way to use numpy on my new macbook pro with an M1 chip.

Use this docker preview for the M1 chip.

E.g. here's a Dockerfile that successfully installs numpy.

FROM python

RUN python3 -m pip install numpy

Build it with:

docker build -t numpytest:latest .

Then run it with:

docker run -it --rm numpytest:latest

And you can verify that numpy is installed and works correctly:

Python 3.9.1 (default, Jan 12 2021, 13:13:57) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.arange(15).reshape(3, 5)
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
>>> 
0

Well I guess it's fixed in unreleased upstream. A pip install of 1.20.2, the latest as of this writing, failed. But I cloned [email protected]:numpy/numpy.git, then did the normal "python setup.py install" in my venv (which is Python 3.9.5 installed via Homebrew) and it seems to work. Haven't thoroughly tested it yet.

0

CrepeGoat's comment worked for me:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.