Error installing numpy on m1 Mac using terminal

I get an error trying to install numpy via terminal on m1 mac, Big Sur V11.2.3

Does anyone have any ideas on how to fix this? Any help would be appreciated :slightly_smiling_face: I’m a complete beginner!

I am doing this as part of the lesson. https://www.codecademy.com/courses/learn-python-3/videos/learn-python3-pipenv

The error is as follows:

$ pipenv --version
pipenv, version 2020.11.15
$ pip install numpy
Collecting numpy
  Downloading numpy-1.20.2.zip (7.8 MB)
     |████████████████████████████████| 7.8 MB 4.6 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 

...
...

  ########### CLIB COMPILER OPTIMIZATION ###########
  Platform      :
    Architecture: unsupported
    Compiler    : gcc
  
  CPU baseline  :
    Requested   : optimization disabled
    Enabled     : none
    Flags       : none
    Extra checks: none
    Requested   : optimization disabled
  
  CPU dispatch  :
    Enabled     : none
    Generated   : none
  CCompilerOpt._cache_write[796] : write cache to path -> /private/var/folders/hk/hrdgtjf97nn876br60rct7ph0000gn/T/pip-install-txk9o_ip/numpy_0f9ab437afb74064bb95c3d2f2e172f4/build/temp.macosx-10.9-universal2-3.9/ccompiler_opt_cache_clib.py
  ----------------------------------------
  ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly
$ 

Ok so I’ve actually solved my own issue! :joy:

Solution =

  1. Quit terminal
  2. Find terminal app icon via finder
  3. Right-click the terminal icon > get info > open using Rossetta
  4. Restart terminal
  5. Do your numpy thang! (Try to install numpy again!)

:crossed_fingers: it will work for you :slightly_smiling_face:

Good luck!

Still doesn’t seem to work when trying to install older versions of numpy e.g 1.15.2. Any solutions appreciated!

What version of Python & pip do you have and how did you install it? (or update it?)

do:
pip -V

I found this thread b/c others have similar issues.

Have you found anything via google? (This is a new issue to me and I’m searching online for info)

1 Like

Hey @lisalisaj

Thanks so much for your help :slightly_smiling_face:

So I found this article which references the rosetta workaround I mention above (which worked, but not for older versions of numpy)

In the article you reference I found that the code

python3.9 -m pip install --only-binary=:all: numpy==1.19.4

works, but not for older versions e.g. 1.15.2

Below are my versions of python and pipenv

dileeparanawake@Dileepas-MBP ~ % python --version
Python 2.7.16
dileeparanawake@Dileepas-MBP ~ % python3 --version
Python 3.9.2
dileeparanawake@Dileepas-MBP ~ % pip --version
pip 21.0.1 from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)
dileeparanawake@Dileepas-MBP ~ % 

I have also tried to install numpy 1.15.2 via the Miniconda package manager as suggested here. Installation of miniconda worked but numpy failed. Looking at the error it might be due to the fact that numpy 1.15.2 requires a python 2 virtual env to run?

✔ Successfully created virtual environment! 
Virtualenv location: /Users/dileeparanawake/.local/share/virtualenvs/clean3-Dj5u4wm3
Creating a Pipfile for this project...
$ conda install numpy==1.15.2
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \ 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                          

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - numpy==1.15.2 -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0']

Your python: python=3.9

I then tried to install a python 2 virtual env (guide). But this seemed to fail

1 Like

Something is deprecated somewhere & incompatible with the environment where you’re installing NumPy…but I’m not entirely sure where. :thinking: Maybe @tgrtim or @el_cocodrilo have some experience with this issue (?)

The latest version of NumPy is 1.20.0 and it fixes some bugs that ppl had when installing.
And, the previous version, 1.19.2 fixes some Cython bugs that ppl encountered.

See here.

2 Likes

There may be some trouble when it comes to the more complex data science packages because of the ARM processor now used (which is less widely supported for now). It would be worthwhile having a web search about this to find useful guidance from anyone who has worked through it. Otherwise it could come to trip you up at unexpected times.

I think those lines there seem to sum up that particular issue though, that version of numpy just doesn’t support 3.9

  - numpy==1.15.2 -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0']

Your python: python=3.9

Docs state 2.7 or 3.4 to 3.7.
https://numpy.org/devdocs/release/1.15.2-notes.html

It’s worth asking if you really need that specific version? If you’re just starting out python’s dependencies can be a whole lot to try and take in at once (even what I included below is quite tame). If you do want to work through it I think you’ll need another version of Python installed.

Do you already have any other versions of python installed other than 3.9? OSX used to include 2.7 (not sure if that’s the case now). If you have 2.7 you could use that (working with virtual envs would be the right option here). Or get another python3 version installed which is supported by that numpy version and use that in your new virtual environment.

One decent option if you’re doing this a lot is pyenv-

Another decent option might be a good package manager for OSX (like homebrew, macports or similar) as they look after quite a lot of the nitty gritty bits for you. I’d suggest looking into them too.

Once you have a working version, see the following for picking a specific version with pipenv-
https://pipenv.pypa.io/en/latest/basics/#specifying-versions-of-python

2 Likes

Thank you for the explanation!
I can +1 on the ease of using Homebrew to install stuff as I used that.

2 Likes

This is very useful @tgrtim - thanks so much :slightly_smiling_face:

I can confirm OSX Arm still comes with 2.7 baked in.

It’s a good question - I don’t actually need that version… yet. I was doing some trouble shooting due to M1 installs failing and went down a rabbit hole! I was trying to figure out how to run 2.7.15 virtual envs and the links you’ve sent look like a great help. Got pyenv installed though.

Thanks again for the help @tgrtim & @lisalisaj

2 Likes

Grand, you’re absolutely right about the rabbit hole (even without ARM support) so I’m glad you got it working. If you’ve got this far you’re probably learning a great deal about how things run even if it’s a bit of an uphill battle.

1 Like

@dileeparanawake This is really it right here :point_up: .

Personally, I wouldn’t suggest worrying about making a virtual environment for Python 2 unless your employer makes you. It’s not supported anymore and it’s only a matter of time until nothing uses it anymore.

If for some reason you do need to do so, there are three easy ways to do it:

  1. Using pipenv:
    • run pipenv --two
    • docs here
  2. If your Python distribution is Anaconda or Miniconda, using conda:
    • run conda create --name py2 python=2.7
    • docs here
  3. Directly download Python 2.7 (e.g., through pyenv on Mac/Linux) and use virtualenv with that python version
    • make sure you’re using python 2
    • run pip install virtualenv
    • run virtualenv env
    • more instructions here

Bonus visual on the number of Python devs who use Python 2:
image

source: https://www.jetbrains.com/lp/python-developers-survey-2020/

3 Likes

@el_cocodrilo Success! :raised_hands: :grinning:

I followed your steps to install python 2.7, ran it and then ran

pip install numpy==1.15.2

and…

Installing collected packages: numpy
  Running setup.py install for numpy ... done
Successfully installed numpy-1.15.2

Success! :partying_face:

Thanks so much for the detailed instructions, advice and help. I didn’t realise it was so uncommon to use older versions @el_cocodrilo so this is helpful, and at least, now I know how to do it.

Grateful to everyone who has helped to solve this and for the great instructions/advice.

Thank you.

2 Likes