anaconda + pytorch 配置 CPU版和GPU版

配置国内源

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

测试

GPU

在这里插入图片描述

CUP

在这里插入图片描述

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值