anaconda中CPU版本的pytorch安装教程

1.建立Pytorch Anaconda虚拟环境

conda create --name pytorch python=3.6 anaconda

在这里插入图片描述
在anaconda装不同环境的好处就是可以把不同的框架独立,互不影响。如果只装pytorch,那么就只有pytorch

2.启动Pytorch Anaconda虚拟环境

activate pytorch

在这里插入图片描述

3.安装Pytorch

pytorch官网版本及安装命令选择
在这里插入图片描述
因为我安装的CPU版本,所以选CPU

4.安装Pytorch(镜像加速)

配置镜像源

Step 1
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Step 2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
Step 3
conda config --set show_channel_urls yes
Step 4
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
Step 5
conda install pytorch torchvision cpuonly
问题1:Invalid spec: =2.7
解决办法:链接
可参考:https://blog.csdn.net/asdfg6541/article/details/104508468/

注意,因为在镜像安装,所以没有官方命令的**-c pytorch**

5.测试

在命令行输入:python,激活python环境

python

然后输入:

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

结果:
在这里插入图片描述

6.安装gpu版本的torch

推荐系统玩家 之 Pytorch,CUDA安装实现GPU计算(Anaconda和Pycharm教程)
注意:conda安装10.2的时候,torch还是安装11.1的

NOTE: 'conda-forge' channel is required for cudatoolkit 11.1
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

win10配置Anaconda清华源镜像,conda下载加速

安装教程-torch-gpu

配置清华源改错

配置清华源的8条命令

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/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

配置完之后用conda下载torch gpu版本速度起飞

常用测试命令

nvcc -V #查看CUDA版本
nvidia-smi #查看GPU使用情况
# 查看是否安装成功,如果没有其它警告,说明安装成功!
import torch
print(torch.__version__)  #注意是双下划线
print(torch.version.cuda)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())

显示:
1.9.1
11.1
True
NVIDIA GeForce RTX 3090

  • 6
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值