我无法通过pip在我的M1 Mac上安装matplotlib。我通过Homebrew安装了Python 3.9.1。我尝试了以下解决方案:Pip install matplotlib fails on M1 Mac但它对我不起作用。
我得到这个长错误:
ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): no suitable image found. Did find:
/opt/homebrew/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so: mach-o, but wrong architecture
/opt/homebrew/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so: mach-o, but wrong architecture
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setup.py", line 256, in <module>
setup( # Finally, pass this all along to distutils to do the heavy lifting.
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 299, in run
self.find_sources()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 306, in find_sources
mm.run()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 541, in run
self.add_defaults()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 577, in add_defaults
sdist.add_defaults(self)
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/sdist.py", line 228, in add_defaults
self._add_defaults_ext()
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/sdist.py", line 311, in _add_defaults_ext
build_ext = self.get_finalized_command('build_ext')
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 299, in get_finalized_command
cmd_obj.ensure_finalized()
File "/opt/homebrew/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 107, in ensure_finalized
self.finalize_options()
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setup.py", line 88, in finalize_options
self.distribution.ext_modules[:] = [
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setup.py", line 91, in <listcomp>
for ext in package.get_extensions()
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setupext.py", line 345, in get_extensions
add_numpy_flags(ext)
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setupext.py", line 468, in add_numpy_flags
import numpy as np
File "/opt/homebrew/lib/python3.9/site-packages/numpy/__init__.py", line 145, in <module>
from . import core
File "/opt/homebrew/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
我可以在我的Rosetta终端上用python2.7导入matplotlib,但我试图用python3来代替。
任何帮助将不胜感激!
6条答案
按热度按时间lbsnaicq1#
2021年11月更新
只需运行以下命令:
在Mac mini(M1,2020)上工作, Monterey 12.0.1。Python 3.9.7
2021年2月答案如下
为了在M1 mac上安装带有pip3的
matplotlib
,首先需要从源代码安装依赖项Cython
,numpy
和Pillow
。1.安装
Cython
1.安装
numpy
1.安装
Pillow
libjpeg
是Pillow所必需的,因此您可能希望通过Brew安装它。1.安装
matplotlib
然后您需要手动下载
qhull
并解压缩存档。(Qhull Downloads上的http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz)您将获得一个名为qhull-2020.2
的文件夹。然后您必须将该文件夹放在matplotlib/build
中。build
文件夹可能不存在,因此您可能需要创建它。最后,以下命令将在您的M1 mac上安装
matplotlib
。在M1 Mac mini(大苏尔11.2.1)的非Rosetta终端上测试Python 3.9.1。
kx7yvsdv2#
我解决这个问题的方法是先卸载自制程序,然后用python3下载matplotlib。之后我用非rosetta终端重新安装了自制程序。我不知道它是如何工作的,因为我对这些东西很陌生,但我猜什么工作。
uqxowvwt3#
我解决了这个问题,因为我安装了两个独立的Python示例,当你运行
which python3
时,你会得到Python安装的路径,检查一下这个路径是否与你安装的Python版本一致。我用
brew uninstall python3
卸载了我用homebrew安装的Python3版本,修复了它。当我再次运行
which python3
时,它显示了一个不同的Python安装路径。然后我运行pip3 install Matplotlib
,我能够导入Matplotlib。i5desfxk4#
1.卸载以下程序包
2.安装matplotlib
2guxujil5#
我最初使用homebrew安装python 3. 9,但我的matplotlib问题通过卸载python并使用从python网站下载的内容重新安装得到了修复(因为架构问题)。
n3schb8v6#
我发现了另一种使用
pyenv
、miniforge
和conda
的好方法。pyenv install miniforge3-4.10
conda create -n env_new python=3.9
conda activate env_new
conda install poetry
peotry new project
poetry add matplotlib
也许它并不完美,但它适用于各种模块,您甚至可以选择
python=3.8
和其他Python版本,所有内容都在M1上运行。