创建文件夹
mkdir d2l
进入文件夹路径
cd d2l
安装miniconda
下载最新版的 Miniconda
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash安装
sh Miniconda3-latest-Linux-x86_64.sh
安装过程一直回车和yes即可,也可以修改安装路径
重启终端就可以使用conda了
解决终端每次打开都直接进入conda的base环境的问题:
conda config --set auto_activate_base false
conda换源
这里换的是清华源,下载会比默认的源快很多
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
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/pytorch/
conda config --set show_channel_urls yes
conda创建虚拟环境
conda create -n env_name python=x.x
其中"env_name"、“x.x” 自己填写,意思是虚拟环境的名字和python的版本号
然后激活虚拟环境
conda activate env_name
安装Pytorch
可以进Pytorch官网,copy对应的命令行下载:https://pytorch.org/get-started/previous-versions/
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1
我是用的是pytorch1.8、cuda11.1,cuda是需要看自己电脑的显卡配置,安装对应版本,这里cudatoolkit虚拟环境里的包,不用在系统安装cuda。
验证pytorch
import torch
print(torch.cuda.is_available()) # True