mac M1安装numpy pandas(by conda)

1,709 阅读3分钟

踩坑历史:

  1. 通过python官网下载了python 3.9.2 然后发现通过pip3 install无法安装numpy 和 pandas. 参照这篇blog通过安装miniforge3 解决 mac M1 安装pandas的问题 但是!但是点进里面的Github链接后发现下载不了!(试了很多次都打不开为什么下面的评论里都能下载 🥲)

  2. 发现miniforge不能用之后,开始寻找其他办法,其中一个就是anaconda(但是这个没有适配arm版本的) 第一次下载anaconda后不能使用,发现是因为没有配置环境变量

发现了一个很有用的blog:Anaconda和conda命令的安装和使用 以下内容为转载:

Anaconda配置安装numpy pandas

配置命令行工具

此时,我们已经安装好的Anaconda的客户端,但是很多情况我们都需要在命令使用conda命令,这个时候在命令行工具输入

conda -version

显示如下(我电脑配置了zsh,所以会显示zsh):

zsh: command not found: conda

显然我们还不能使用conda命令。

1. zsh配置流程

找到.zshrc文件,一般在/Users/{username}/.zshrc,其中{username}是你当前Mac的用户名字哦。 用记事本打开.zshrc文件(你也可以使用vim命令来编辑),在该文件的最后一行添加:

export PATH="/opt/anaconda3/bin:$PATH"

然后保存 命令行工具进入到/Users/{username}目录下,执行

source .zshrc

接着执行

conda --version

就可以看到输出的版本号了:

conda 4.9.2
2. bash_profile 配置

找到.bash_profile文件,一般在/Users/{username}/.bash_profile,其中{username}是你当前Mac的用户名字哦。 用记事本打开.bash_profile文件(你也可以使用vim命令来编辑),在该文件的最后一行添加:

export PATH="/opt/anaconda3/bin:$PATH"

然后保存 命令行工具进入到/Users/{username}目录下,执行

source .bash_profile

接着执行

conda --version

就可以看到输出的版本号了:

conda 4.9.2

添加常用源

由于网络问题,有些时候直接同国外下载库会比较慢,我们可以给conda配置国内的镜像源,添加国内的镜像源命令如下:

  1. 清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
  1. 添加中科院源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

查看是否添加成功可是用命令

conda config --show

channels这个字段这里显示已经添加的源

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults

conda常用命令

升级

conda update conda  # 更新 conda
conda update anaconda # 更新 anaconda
conda update anaconda-navigator    #update最新版本的anaconda-navigator  
conda update python # 更新 python

管理环境

conda env list  #显示所有的虚拟环境
conda create --name fulade python=3.7 # 创建一个名为 fulade 环境,指定Python版本是3.7
activate fulade  # 激活名为 fulade 的环境 (Windows 使用)
source activate fulade  # 激活名为 fulade 的环境 (Linux & Mac使用用)
deactivate fulade   #关闭名为 fulade的环境( Windows使用)
source deactivate fulade  # 关闭名为 fulade的环境(Linux & Mac使用)
conda remove --name fulade --all # 删除一个名为 fulade 的环境
conda create --name newname --clone oldname # 克隆oldname环境为newname环境

package管理

conda list  #查看当前环境下已安装的package
conda search numpy # 查找名为 numpy 的信息 package 的信息
conda install numpy  # 安装名字为 fulade 的package 安装命令使用-n指定环境 --channel指定源地址
conda install -n fulade numpy  # 在fulade的环境中 安装名字为 fulade 的package
conda install --channel https://conda.anaconda.org/anaconda tensorflow=1.8.0  # 使用地址 https://conda.anaconda.org/anaconda 来安装tensorflow
conda update numpy   #更新numpy package
conda uninstall numpy   #卸载numpy package
conda install seaborn #包含matplotlib
conda install pandas

清理conda

conda clean -p      //删除没有用的包
conda clean -t      //删除tar包
conda clean -y --all //删除所有的安装包及cache