MacBook M1安装Numpy,Pandas,Matplotlib
我的环境
MacBook M1 + Python3.9 + Pycharm 2021
安装遇到的问题
当我们尝试使用 pip3 install numpy
或者 pip3 install pandas
时,它会显示以下的错误
错误 ①
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
错误 ②
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
常见的Numpy、Pandas安装方法总结
方法一 :通过 Miniforge
安装
这种方法是目前最普遍的方法,但是在我使用了该方法安装后,Pycharm
中无法 import
,运行后找不到 numpy
和 pandas
模块,这种方法可以直接去搜,不再赘述,贴个链接:
macos - Trouble installing Pandas on new MacBook Air M1 - Stack Overflow
方法二:通过 tensflow
安装
通过 tensflow_macos
安装,但是仅限于 Python3.8
,否则会遇到版本不兼容的错误,找了一个视频教学,但是这个方法对我不适用,我在安装的时候再次遇到了错误,贴个教学视频链接
Install tensorflow, matplotlib, pandas, jupyter notebook on MacBook with M1 chip - YouTube
方法三:通过 Rosetta
安装
下载 iterm
,依次点击 应用程序 -> 右键显示简介-> 使用Rosetta打开
,打开后直接使用以下命令安装亲测没问题,但是如果你在 arm
的应用例如 Pycharm
中使用该模块依旧报错,说到底:X86
编译后只能使用 X86
,arm
编译后只能使用 arm
,这种方法对我不适用,贴个教学视频链接:
Install Python with NumPy SciPy Matplotlib on macOS Big Sur Apple Silicon M1 - YouTube
简单粗暴,直接安装Numpy、Pandas,亲测高效(终极方法)
啥都不说了,直接肝,简单粗暴,安装测试
① 安装 Cython
kylewhite@kyledeMacBook-Pro ~ % pip3 install cython --no-use-pep517
Collecting cython
Using cached Cython-0.29.22-py2.py3-none-any.whl (980 kB)
Installing collected packages: cython
Successfully installed cython-0.29.22
② 安装 Numpy
kylewhite@kyledeMacBook-Pro ~ % pip3 install numpy --no-use-pep517
Collecting numpy
Using cached numpy-1.20.1.zip (7.8 MB)
Using legacy 'setup.py install' for numpy, since package 'wheel' is not installed.
Installing collected packages: numpy
Running setup.py install for numpy ... done
Successfully installed numpy-1.20.1
③ 安装 Pandas
kylewhite@kyledeMacBook-Pro ~ % pip3 install pandas --no-use-pep517
Collecting pandas
Using cached pandas-1.2.4.tar.gz (5.5 MB)
Requirement already satisfied: python-dateutil>=2.7.3 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pandas) (2021.1)
Requirement already satisfied: numpy>=1.16.5 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pandas) (1.20.3)
Requirement already satisfied: six>=1.5 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Using legacy 'setup.py install' for pandas, since package 'wheel' is not installed.
Installing collected packages: pandas
Running setup.py install for pandas ... done
Successfully installed pandas-1.2.4
使用 Pycharm
测试一波:
安装Matplotlib
直接安装,没什么问题,可能要警告或者错误但是没关系,只要显示 Successful installed
就可以了
pip3 install matplotlib
测试一波