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 ,运行后找不到 numpypandas 模块,这种方法可以直接去搜,不再赘述,贴个链接:

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 编译后只能使用 X86arm 编译后只能使用 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

测试一波
在这里插入图片描述

  • 11
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
### 回答1: numpypandasmatplotlibPython中常用的数据处理和可视化库。安装这些库可以使用pip命令,具体步骤如下: 1. 打开命令行窗口(Windows用户可以按下Win+R键,输入cmd并回车打开命令行窗口)。 2. 输入以下命令安装numpy: ``` pip install numpy ``` 3. 输入以下命令安装pandas: ``` pip install pandas ``` 4. 输入以下命令安装matplotlib: ``` pip install matplotlib ``` 5. 等待安装完成即可。 注意:在安装这些库之前,需要先安装Python环境。如果你还没有安装Python,可以从官网下载安装包进行安装。 ### 回答2: NumPyPandasMatplotlibPython中最常用的科学计算库之一,它们可以帮助我们更方便地进行数据处理、分析和可视化。在开始使用这些库前,我们需要先将它们安装在我们的机器上。 1. 安装NumPy NumPyPython数值计算库。它可以帮助我们在Python中完成数学运算、线性代数操作和数组处理等工作。在安装NumPy之前,我们需要先安装Python以及Python包管理器pip。 我们可以通过pip命令来安装NumPy。在终端中输入以下命令即可: ``` pip install numpy ``` 2. 安装Pandas Pandas是一个数据分析库,它能够帮助我们加载、处理和分析各种类型的数据集。与NumPy一样,我们可以用pip来安装Pandas。在终端中输入以下命令即可: ``` pip install pandas ``` 3. 安装Matplotlib MatplotlibPython中最流行的数据可视化库,它能够帮助我们绘制各种类型的图表,包括线图、散点图、柱状图和饼图等。在安装Matplotlib之前,我们需要确保已经安装NumPyPandas。接下来,在终端中输入以下命令即可: ``` pip install matplotlib ``` 如果你希望使用更加方便的Python开发环境,比如Anaconda或者Jupyter Notebook,这些库通常已经预先安装好了。你只需要在你的代码中引入即可开始使用它们。 总之,安装NumPyPandasMatplotlib非常简单,只需要通过pip命令就可以完成。如果你遇到了任何问题,可以查看官方文档或者在Python社区中寻求帮助。 ### 回答3: numpypandasmatplotlibPython科学计算必不可少的三个库,它们在数据处理、数据可视化和科学计算领域被广泛使用。本文将介绍安装这三个库的步骤。 1. 安装numpy 安装numpy的最简单方法是使用pip命令,该命令默认安装最新版本的numpy。在命令行中输入以下命令即可安装numpy: ``` pip install numpy ``` 2. 安装pandas 安装pandas也可以使用pip命令,同样默认安装最新版本的pandas。在命令行中输入以下命令即可安装pandas: ``` pip install pandas ``` 3. 安装matplotlib 安装matplotlib也可以使用pip命令,但我们还需要安装依赖项。在命令行中输入以下命令即可安装: ``` pip install numpy pip install pandas pip install matplotlib ``` 以上命令将numpypandasmatplotlib安装到您的计算机上。但是,在某些情况下,安装这些库可能会遇到以下问题: - 不能访问pypi.org或其他软件包索引。 - 依赖项安装不正确。 - 其他Python版本的库和包。 如果您遇到这样的问题,您需要执行以下操作: - 检查您的网络连接。 - 明确依赖关系。 - 使用虚拟环境来避免其他库和包的干扰。 为了确保依赖项正确安装,建议使用虚拟环境来运行这些库。虚拟环境本质上是Python环境的独立副本,可以在其中安装特定版本的库,而不会影响到其他Python环境。要创建虚拟环境,请执行以下步骤: 1. 安装虚拟环境包 在命令行中输入以下命令以安装虚拟环境包: ``` pip install virtualenv ``` 2. 创建虚拟环境 在命令行中输入以下命令以创建一个名为myenv的虚拟环境: ``` virtualenv myenv ``` 3. 激活虚拟环境 在Windows系统中,可以通过以下命令激活虚拟环境: ``` myenv\Scripts\activate ``` 在Linux系统中,可以通过以下命令激活虚拟环境: ``` source myenv/bin/activate ``` 4. 安装python和依赖项 在激活虚拟环境后,可以安装Python和所需的依赖项(numpypandasmatplotlib)。在命令行中输入以下命令: ``` pip install numpy pip install pandas pip install matplotlib ``` 5. 将虚拟环境导出 导出虚拟环境可以使您在不同的计算机上共享虚拟环境。在虚拟环境激活状态下,执行以下命令即可导出: ``` pip freeze > requirements.txt ``` 6. 在其他计算机上导入虚拟环境 在其他计算机上使用虚拟环境,需要在虚拟环境目录中创建一个名为requirements.txt的文件,该文件列出了虚拟环境所需的库和版本信息。在命令行中输入以下命令即可导入: ``` pip install -r requirements.txt ``` 总之,numpypandasmatplotlib安装非常简单,只需在命令行中执行pip命令即可。如果遇到依赖关系或运行其他Python版本的问题,建议使用虚拟环境来安装和运行这些库。希望这篇文章对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值