Ubuntu/Linux 安装Anconda、PyTorch、检测cuDNN、Jupyter Notebook

13 篇文章 0 订阅
8 篇文章 0 订阅
本文详细指导了在Ubuntu/Linux系统上安装Anaconda3、设置GPU环境(包括CUDA和cuDNN)、创建并激活虚拟环境、安装PyTorch(推荐1.10版本),以及检查和解决cuDNN版本兼容问题。最后介绍了如何安装和启动JupyterNotebook。
摘要由CSDN通过智能技术生成

1. 提前准备

显卡驱动:Ubuntu/Linux 安装GPU 驱动&检测(PyTorch准备)
CUDA:Ubuntu/Linux 安装CUDA、检测(PyTorch准备)
cuDNN:Ubuntu/Linux 安装cuDNN、检测(PyTorch准备)

2. 安装Anaconda 3-2023.09

链接: 官网
其他参考: 其他参考

Debain 安装提前下载
Anaconda版本:repo.anaconda.com/archive/

sudo apt update && sudo apt upgrade -y
sudo apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6
sudo apt install curl
curl -O https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh

安装

find / -name "Anaconda3-2023.09-0-Linux-x86_64.sh"
bash **path**/Anaconda3-2023.09-0-Linux-x86_64.sh

输入“yes” 使得SHELL之后可以直接使用conda init

2.1. 检查Anaconda安装

conda info
conda -V

3. 建立环境&安装PyTorch

3.1. 虚拟环境

conda create -n base_pytorch python=3.7 # 创建base_pytorch python3.7 环境
conda activate base_pytorch # 激活环境
conda info --envs # 检查环境

3.2. PyTorch版本选择

链接: https://pytorch.org/get-started/locally/

最好使用低版本1.10

 pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio==0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

遇到问题可以使用官网的代码: https://pytorch.org/get-started/previous-versions/

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 -c pytorch

在这里插入图片描述

4. 全面检查 PyTorch、CUDA、cuDNN

原文链接

4.1. 检查PyTorch

python
import torch
print(torch.__version__) # 查看pytorch版本1.11.0

4.2. 全面检查CUDA

python
import torch
torch.cuda.is_available()  # cuda是否可用 True
print(torch.version.cuda)  # 查看pytorch 对应的cuda版本11.3
torch.cuda.device_count()  # 返回gpu数量
torch.cuda.get_device_name(0) # 返回gpu名字,设备索引默认从0开始
torch.cuda.current_device()  # 返回当前设备索引

4.3. 检测cudnn可用性

python
import torch
print(torch.backends.cudnn.version()) # 8200
a = torch.tensor(1.)
a.cuda() # tensor(1., device='cuda:0')
from torch.backends import cudnn # 若正常则静默
cudnn.is_available() # 若正常返回True
cudnn.is_acceptable(a.cuda()) # 若正常返回True

5. cuDNN 版本问题解决

参考文章:Ubuntu/Linux 安装cuDNN、检测、版本修改(PyTorch准备)

RuntimeError: cuDNN version incompatibility: PyTorch was compiled against (8, 9, 2) but found runtime version (8, 7, 0). PyTorch already comes bundled with cuDNN. One option to resolving this error is to ensure PyTorch can find the bundled cuDNN.Looks like your LD_LIBRARY_PATH contains incompatible version of cudnnPlease either remove it from the path or install cudnn (8, 9, 2)

6. 安装Jupyter Notebook

conda install jupyter

conda activate base
conda update conda # 一定要在base先升级一下
conda activate base_pytorch
conda install jupyter
cd /home/×××/ #到想存放jupyter notebook的文件夹
jupyter notebook
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值