Pip在M1 Mac上安装matplotlib失败

15
我在我的M1 Mac上通过pip安装matplotlib时遇到了困难。我已经通过Homebrew安装了Python 3.9.1。
当运行pip3 install matplotlib时,安装程序尝试安装最新版本matplotlib 3.3.4。安装程序在一段时间后卡住并打印出一个巨大的错误消息。之后它尝试安装版本3.3.3,然后再次发生相同的情况,以此类推。出了什么问题?
以下是部分错误消息:
    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

1
你正在从源代码构建,但很可能缺少构建依赖项。 - FalseDev
3个回答

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

这对我有用,在此时它安装了numpy 1.20.1。

相同的Python版本(来自Homebrew的3.9.1)。


1
运行得非常好。谢谢。OSX: 10.2.3 Python: 3.9.4 在虚拟环境中。安装了numpy 1.20.2,matplotlib 3.4.1和cython 0.29.22。Pandas是一个问题。我使用了你用于numpy的相同命令行。它成功安装了pandas 1.2.4。供参考: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
4
无法在macOS Big Sur 11.3的Python 3.9.6上运行。解决方法是安装较旧的版本:sudo pip3 install matplotlib==3.2.2,尽管当前最新版本是matplotlib==3.4.2 - ynn
这是最终的解决方案吗?我正在使用 Python 3.9.4。 - yts61

3
  1. 安装Miniforge,选择适用于arm64 (Apple Silicon) 的最新版本(安装程序在此处:installer here)。

  2. 现在为您所拥有的任何Python版本创建一个conda环境(我正在运行3.9.2)。

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

如果你试图从wheels/pip开始,尝试让所有不同的程序包正常工作将令你发疯。


-1
尝试在我的 M1 MacBook(Big Sur 11.6,Python 3.9.7)上安装 matplotlib,但出现了以下错误:
Invalid configuration `arm64-apple-darwin20.6.0': machine `arm64-apple' not recognized`

我通过这条评论https://github.com/matplotlib/matplotlib/issues/20661#issuecomment-889189712的帮助成功解决了问题并安装了matplotlib。

总结:

$ cat <<EOF > setup.cfg
[libs]
system_freetype = True
EOF
$ export MPLSETUPCFG=$PWD/setup.cfg
$ python -m pip install matplotlib

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接