15

I'm having difficulties installing matplotlib through pip on my M1 Mac. I have Python 3.9.1 installed through Homebrew.

When running pip3 install matplotlib the installer tries installing the newest version, matplotlib 3.3.4. The installer gets stuck and prints a huge error message after some time. After this it tries installing version 3.3.3 after which the same happens again, and so on. What goes wrong?

Here is some of the error message:

    william@Williams-MacBook-Pro ~ % pip3 install matplotlib
Collecting matplotlib
  Using cached matplotlib-3.3.4.tar.gz (37.9 MB)
    ERROR: Command errored out with exit status 1:
     command: /opt/homebrew/opt/python@3.9/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/yb/rgjfc7ws25ddwd07x96f4fmw0000gn/T/pip-install-h7oltt2f/matplotlib_1ad1e28a38b14b40ae2bcaa7f9b01cab/setup.py'"'"'; __file__='"'"'/private/var/folders/yb/rgjfc7ws25ddwd07x96f4fmw0000gn/T/pip-install-h7oltt2f/matplotlib_1ad1e28a38b14b40ae2bcaa7f9b01cab/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/yb/rgjfc7ws25ddwd07x96f4fmw0000gn/T/pip-pip-egg-info-0jjax4jc
         cwd: /private/var/folders/yb/rgjfc7ws25ddwd07x96f4fmw0000gn/T/pip-install-h7oltt2f/matplotlib_1ad1e28a38b14b40ae2bcaa7f9b01cab/
    Complete output (2287 lines):
      ERROR: Command errored out with exit status 1:
       command: /opt/homebrew/opt/python@3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/yb/rgjfc7ws25ddwd07x96f4fmw0000gn/T/tmp3p0is_vc
           cwd: /private/var/folders/yb/rgjfc7ws25ddwd07x96f4fmw0000gn/T/pip-wheel-5rqmhbah/numpy_cefeff1e3acc4faea4c06d0f4597b2da
Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
williameo
  • 151
  • 1
  • 1
  • 4

3 Answers3

25
python3 -m pip install cython   
python3 -m pip install --no-binary :all: --no-use-pep517 numpy
brew install libjpeg
python3 -m pip install matplotlib

Worked for me, at this time it installed numpy 1.20.1.

Same Python version (3.9.1) from Homebrew.

Marijn
  • 1,109
  • 8
  • 9
  • 1
    Worked very well. Thank you. OSX: 10.2.3 Python: 3.9.4 inside virtualenv. Installed numpy 1.20.2, matplotlib 3.4.1, with cython 0.29.22. Pandas was a problem. I used the same line you did for numpy. It installed pandas 1.2.4 ok. For reference: ``` black 20.8b1 Cython 0.29.22 flake8 3.9.0 isort 5.8.0 jupyter 1.0.0 matplotlib 3.4.1 numpy 1.20.2 pandas 1.2.4 pylint 2.7.4 ``` – JSBach Apr 14 '21 at 07:03
  • 4
    Not working on macOS BigSur 11.3, Python 3.9.6. The solution was installing the older version: `sudo pip3 install matplotlib==3.2.2` though the current latest version is `matplotlib==3.4.2`. – ynn Jul 09 '21 at 13:23
  • so is this the final solution? I am on python 3.9.4 – yts61 Jul 15 '21 at 12:59
3
  1. Install Miniforge for arm64 (Apple Silicon)latest installer here: installer here

  2. Now create a conda environment for whatever version you have (I'm running 3.9.2)

conda create -n cenv python=3.9.2
conda activate cenv
conda install matplotlib

You will drive yourself nuts trying to get all the different packages working if you try to go from wheels/pip, at time of writing.

floatingice
  • 179
  • 6
-1

Trying to install matplotlib on my M1 Macbook (Big Sur 11.6, python 3.9.7), I was getting:

Invalid configuration `arm64-apple-darwin20.6.0': machine `arm64-apple' not recognized`

I was able to resolve the issue and install matplotlib with help from this comment: https://github.com/matplotlib/matplotlib/issues/20661#issuecomment-889189712

Summary:

$ cat <<EOF > setup.cfg
[libs]
system_freetype = True
EOF
$ export MPLSETUPCFG=$PWD/setup.cfg
$ python -m pip install matplotlib
n8henrie
  • 2,737
  • 3
  • 29
  • 45