Mac系统搭建深度学习环境详细教程

Anaconda 和 Miniconda作用是一样的,装一个即可。
安装过程是一样的,下面以Miniconda为例编写的教程。

下载Miniconda

Miniconda的官网:https://docs.conda.io/en/latest/miniconda.html

官网下载速度慢,直接去清华镜像网站下载红框,框出来的版本:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
Mac系统搭建深度学习环境详细教程_第1张图片

安装Miniconda

将下载好的Miniconda文件放到home目录下
Mac系统搭建深度学习环境详细教程_第2张图片
出现许可协议,如下图:
Mac系统搭建深度学习环境详细教程_第3张图片
在这里插入图片描述
Mac系统搭建深度学习环境详细教程_第4张图片

提示:安装需要时间,请耐心等待

在这里插入图片描述
Mac系统搭建深度学习环境详细教程_第5张图片

虚拟环境常用操作

更换国内源(国外的同学请忽略此步)

执行:vim .condarc,将以下内容复制到.condarc文件中

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

在这里插入图片描述
Mac系统搭建深度学习环境详细教程_第6张图片

vim操作命令请参考:https://blog.csdn.net/qq_28168421/article/details/85241669

创建虚拟环境

指令:conda create -n tf2 python=3.6 -yMac系统搭建深度学习环境详细教程_第7张图片

查看虚拟环境

指令:conda env list
Mac系统搭建深度学习环境详细教程_第8张图片

激活虚拟环境

指令:source activate tf2
在这里插入图片描述

安装函数库

指令:pip install numpy,安装numpy
Mac系统搭建深度学习环境详细教程_第9张图片
如果下载速度较慢,可以采用下面的安装命令,采用国内的阿里源

pip install numpy -i "https://mirrors.aliyun.com/pypi/simple"

退出虚拟环境

指令:conda deactivate
在这里插入图片描述

常用函数库安装

numpy 
dataclasses 
pandas 
matplotlib 
opencv-python 
opencv-contrib-python 
pillow 
scikit-learn 
scipy 
absl-py==0.9 
tensorflow 
tensorflow_datasets
torch==1.6.0
torchvision==0.7.0
-i "https://mirrors.aliyun.com/pypi/simple"

同时安装多个函数库

第一种方法:

pip install numpy dataclasses pandas matplotlib opencv-python opencv-contrib-python pillow scikit-learn scipy absl-py==0.9 tensorflow tensorflow_datasets -i "https://mirrors.aliyun.com/pypi/simple"

第二种方法:

创建一个txt文件,命名为requirements.txt
在这里插入图片描述
Mac系统搭建深度学习环境详细教程_第10张图片

此图与常用库不符,只作为参考
创建好requirements.txt,将常用函数库的代码复制进去即可。

wq退出并保存

在终端执行指令:pip install -r requirements.txt
在这里插入图片描述

其他操作

缺少函数库报错的解决方案

举例说明,缺少什么函数库,就安装什么即可,如下图所示:Mac系统搭建深度学习环境详细教程_第11张图片

删除虚拟环境

指令:conda remove -n tf2 --all
Mac系统搭建深度学习环境详细教程_第12张图片

此操作了解即可,不必操作,一般是不会删除虚拟环境的

到这里利用miniconda搭建深度学习环境就结束了,如果有哪里错误或者更好的方法,欢迎大家留言_

你可能感兴趣的:(环境安装)