linux系统 anaconda环境下安装gpu版本的pytorch

问题

最近新建了一个conda环境,想要在里面安装pytorch,在官网选择了gpu版本,按照官网给出的命令用conda安装,却总是装成cpu版本,试了很多博客的解决方案,但都没有成功,遇到各种新问题。

最终解决方案

改用pip安装,根据自己的Python和CUDA版本,分别安装torch, torchvision和torchaudio。

pip install --default-time=300 https://download.pytorch.org/whl/cu113/torch-1.10.0%2Bcu113-cp36-cp36m-linux_x86_64.whl
pip install https://download.pytorch.org/whl/cu113/torchvision-0.11.1%2Bcu113-cp36-cp36m-linux_x86_64.whl
pip install https://download.pytorch.org/whl/cu113/torchvision-0.11.1%2Bcu113-cp36-cp36m-linux_x86_64.whl

安装过程中出现依赖问题RequiredDependencyException,从报错的信息看需要安装pillow:

pip install pillow==8.0.0

如遇此类依赖问题,先安装缺少的包,再继续安装pytorch即可。
测试是否可用:

import torch

if_cuda = torch.cuda.is_available()
print("if_cuda=",if_cuda)
gpu_count = torch.cuda.device_count()
print("gpu_count=",gpu_count)

若输出为True和gpu数量,表示gpu版本的pytorch可用。

后来试了另一种更简单的方法:

conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge

你可能感兴趣的:(神经网络,深度学习)