配置国内源
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/
# 配置国内源,安装PyTorch用
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
# 删除所有channels
conda remove-key channels
# 删除指定channels
conda remove channels $name
创建环境
conda create -n pytorch python=3.7
进入pytorch环境
conda activate pytorch
自动配置
GPU
在porch官网,选择配置。
注意1:(GPU)有Nvidia的显卡才能选择CUDA,
注意2:使用国内镜像要省略命令 -c pytorch -c nvidia
conda install pytorch torchvision torchaudio pytorch-cuda=11.6
或者(巨慢)
# 指定一个pytorch版本
conda install pytorch=1.12.0
CUP
# cpu最新版本
pip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple
指定版本下载
pip install torch==版本号 torchvision==版本号 torchaudio==版本号 -i https://pypi.tuna.tsinghua.edu.cn/simple
手动配置GPU
在cuda的文档中下在对应版本的cuda+torch+torch+torchvision+torchaudio
例如:cuda11.6版的torch1.12.0、python3.7、windows,与之相匹配的是
cuda11.6版的torchaudio0.12.0、python3.7、windows,
cuda11.6版的torchvision0.13.0、python3.7、windows
手动安装
# 进入pytorch环境打开文件下载目录
(pytorch) PS C:\Users\name> cd 'C:\Download\'
# 安装 cu116 和 torch-1.12.0
(pytorch) PS C:\Download> pip install torch==1.12.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
(pytorch) PS C:\Download> pip install .\torch-1.12.0+cu116-cp37-cp37m-win_amd64.whl
# 安装torchaudio和torchvision
(pytorch) PS C:\Download> pip install .\torchaudio-0.12.0+cu116-cp37-cp37m-win_amd64.whl
(pytorch) PS C:\Download> pip install .\torchvision-0.13.0+cu116-cp37-cp37m-win_amd64.whl