在 WSL-NVIDIA-Workbench(NVIDIA AI Workbench & Ubuntu 22.04)中

安装 Anaconda、CUDA 13.0、cuDNN 9.12 及 PyTorch
 

步骤也可参阅:

在WSL2-Ubuntu中安装Anaconda、CUDA13.0、cuDNN9.12及PyTorch(含完整环境验证)-CSDN博客

【笔记】NVIDIA AI Workbench 安装记录_NVIDIA AI Workbench使用指南-CSDN博客

【深度学习环境搭建】WSL-NVIDIA-Workbench 中安装 Anaconda-CSDN博客

【笔记】NVIDIA AI Workbench 中 sudo 密码问题排查与解决_[sudo] password for-CSDN博客

【笔记】NVIDIA AI Workbench 中安装 CUDA 12.9_cuda12.9安装-CSDN博客

【笔记】NVIDIA AI Workbench 中安装 cuDNN 9.10.2_apt安装cudnn-CSDN博客

【笔记】NVIDIA AI Workbench 中安装 PyTorch_pytorch 2.8.0-CSDN博客



0 环境说明

项目 实际值 & 关键说明
发行版 NVIDIA-Workbench(WSL2-Ubuntu 22.04 纯净镜像,无预装 Python、Anaconda、CUDA 依赖)
宿主驱动与 CUDA 兼容性 宿主 Windows 安装 NVIDIA 驱动 581.08(通过 nvidia-smi 检测),该驱动原生支持 CUDA 13.0nvidia-smi 显示 CUDA Version: 13.0,即驱动最高兼容 CUDA 13.0)
目标 在 NVIDIA-Workbench 中(NVIDIA AI Workbench)安装并启用 CUDA 13.0 全链路(驱动匹配,无需降级适配,PyTorch 可直接调用兼容的 CUDA 版本)

1 首次更新系统

sudo apt update && sudo apt upgrade -y

  • 命令作用:更新系统软件源及依赖库,避免后续安装时因依赖缺失导致失败
  • 预期输出(只截取了部分关键片段):
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
...
Fetched 21.8 MB in 8s (2684 kB/s)
77 upgraded, 46 newly installed, 0 to remove and 9 not upgraded.
...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...


2 安装 Anaconda(保持不变,补充下载校验)

2.1 下载并执行安装脚本

cd /tmp
# 下载 Anaconda 3 2025.07 稳定版(适配 Python 3.12)
wget https://repo.anaconda.com/archive/Anaconda3-2025.07-Linux-x86_64.sh
# 执行安装(按提示输入 yes 并确认路径)
bash Anaconda3-2025.07-Linux-x86_64.sh

  • 关键交互:最终提示 Do you wish the installer to initialize Anaconda3? 时输入 yes,其他交互默认按 回车 键确认并继续即可,最新版本一般无须过多干预。

2.2 验证安装

source ~/.bashrc
conda --version

  • 预期输出

conda 25.07.1


3 安装 CUDA Toolkit 13.0

CUDA 与 cuDNN 免登录下载政策详解(基于官方权威信息)_cudnn下载-CSDN博客

CUDA Toolkit 13.0 Downloads | NVIDIA Developer

3.1 复制 NVIDIA 官网安装命令

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-13-0

3.2 安装 CUDA 13.0 工具包

在 NVIDIA-Workbench 终端中粘贴全部命令并按 回车 键执行:

  • 预期输出
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-13-0
--2025-08-29 19:20:07--  https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
Connecting to 127.0.0.1:7897... connected.
Proxy request sent, awaiting response... 200 OK
Length: 4328 (4.2K) [application/x-deb]
Saving to: ‘cuda-keyring_1.1-1_all.deb’

cuda-keyring_1.1-1_all.deb                                                  100%[===========================================================================================================================================================================================>]   4.23K  --.-KB/s    in 0s      

2025-08-29 19:20:10 (1.90 GB/s) - ‘cuda-keyring_1.1-1_all.deb’ saved [4328/4328]
……省略
配置环境变量

# 追加 CUDA 环境变量至 bash 配置文件(永久生效)
echo 'export CUDA_HOME=/usr/local/cuda-13.0' >> ~/.bashrc
echo 'export PATH=$CUDA_HOME/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$CONDA_PREFIX/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

# 验证环境变量
echo $CUDA_HOME

  • 预期输出
/usr/local/cuda-13.0

3.3 验证 CUDA 工具包安装

nvcc --version

# 或
nvcc -V

  • 预期输出(显示 CUDA 13.0 编译器版本):
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Wed_Jul_16_07:30:01_PM_PDT_2025
Cuda compilation tools, release 13.0, V13.0.48
Build cuda_13.0.r13.0/compiler.36260728_0


4 安装 cuDNN 9.12

CUDA 深度神经网络库 (cuDNN) | NVIDIA 开发者

conda install nvidia::cudnn cuda-version=13

conda install nvidia::cudnn=9.12 cuda-version=13
  • 预期输出(显示 cuDNN 相关库文件):
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ conda install nvidia::cudnn cuda-version=13
Channels:
 - defaults
 - nvidia
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/workbench/anaconda3

  added / updated specs:
    - cuda-version=13
    - nvidia::cudnn


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    ca-certificates-2025.7.15  |       h06a4308_0         126 KB
    certifi-2025.8.3           |  py312h06a4308_0         159 KB
    conda-24.11.3              |  py312h06a4308_0         1.1 MB
    cuda-nvrtc-13.0.48         |       h432ef4e_0        65.3 MB  nvidia
    cuda-version-13.0          |                3          17 KB  nvidia
    cudnn-9.12.0.46            |       ha5d3b03_0          13 KB  nvidia
    libcublas-13.0.0.19        |       h49e6dd0_0       374.7 MB  nvidia
    libcudnn-9.12.0.46         |       h97f9646_0       276.1 MB  nvidia
    libcudnn-dev-9.12.0.46     |       ha5d3b03_0          37 KB  nvidia
    openssl-3.0.17             |       h5eee18b_0         5.2 MB
    ------------------------------------------------------------
                                           Total:       722.8 MB

The following NEW packages will be INSTALLED:

  cuda-nvrtc         nvidia/linux-64::cuda-nvrtc-13.0.48-h432ef4e_0 
  cuda-version       nvidia/noarch::cuda-version-13.0-3 
  cudnn              nvidia/linux-64::cudnn-9.12.0.46-ha5d3b03_0 
  libcublas          nvidia/linux-64::libcublas-13.0.0.19-h49e6dd0_0 
  libcudnn           nvidia/linux-64::libcudnn-9.12.0.46-h97f9646_0 
  libcudnn-dev       nvidia/linux-64::libcudnn-dev-9.12.0.46-ha5d3b03_0 

The following packages will be UPDATED:

  ca-certificates                      2024.9.24-h06a4308_0 --> 2025.7.15-h06a4308_0 
  certifi                         2024.8.30-py312h06a4308_0 --> 2025.8.3-py312h06a4308_0 
  conda                              24.9.2-py312h06a4308_0 --> 24.11.3-py312h06a4308_0 
  openssl                                 3.0.15-h5eee18b_0 --> 3.0.17-h5eee18b_0 


Proceed ([y]/n)? y


Downloading and Extracting Packages:
                                                                                                                                                                                                                                                                                                                
Preparing transaction: done                                                                                                                                                                                                                                                                                     
Verifying transaction: done                                                                                                                                                                                                                                                                                     
Executing transaction: done                                                                                                                                                                                                                                                                                     
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ conda list | grep cudnn  # 输出“cudnn                     9.12.0.46          h2b6041c_0    nvidia”                                                                                                                                                       
cudnn                     9.12.0.46            ha5d3b03_0    nvidia
libcudnn                  9.12.0.46            h97f9646_0    nvidia
libcudnn-dev              9.12.0.46            ha5d3b03_0    nvidia
nvidia-cudnn-cu12         9.8.0.87                 pypi_0    pypi
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ ls $CONDA_PREFIX/lib/libcudnn*  # 显示libcudnn.so、libcudnn_static.a等文件                                                                                                                                                                               
/home/workbench/anaconda3/lib/libcudnn.so         /home/workbench/anaconda3/lib/libcudnn_adv.so.9.12.0           /home/workbench/anaconda3/lib/libcudnn_engines_precompiled.so.9            /home/workbench/anaconda3/lib/libcudnn_graph.so         /home/workbench/anaconda3/lib/libcudnn_heuristic.so.9.12.0
/home/workbench/anaconda3/lib/libcudnn.so.9       /home/workbench/anaconda3/lib/libcudnn_cnn.so                  /home/workbench/anaconda3/lib/libcudnn_engines_precompiled.so.9.12.0       /home/workbench/anaconda3/lib/libcudnn_graph.so.9       /home/workbench/anaconda3/lib/libcudnn_ops.so
/home/workbench/anaconda3/lib/libcudnn.so.9.12.0  /home/workbench/anaconda3/lib/libcudnn_cnn.so.9                /home/workbench/anaconda3/lib/libcudnn_engines_runtime_compiled.so         /home/workbench/anaconda3/lib/libcudnn_graph.so.9.12.0  /home/workbench/anaconda3/lib/libcudnn_ops.so.9
/home/workbench/anaconda3/lib/libcudnn_adv.so     /home/workbench/anaconda3/lib/libcudnn_cnn.so.9.12.0           /home/workbench/anaconda3/lib/libcudnn_engines_runtime_compiled.so.9       /home/workbench/anaconda3/lib/libcudnn_heuristic.so     /home/workbench/anaconda3/lib/libcudnn_ops.so.9.12.0
/home/workbench/anaconda3/lib/libcudnn_adv.so.9   /home/workbench/anaconda3/lib/libcudnn_engines_precompiled.so  /home/workbench/anaconda3/lib/libcudnn_engines_runtime_compiled.so.9.12.0  /home/workbench/anaconda3/lib/libcudnn_heuristic.so.9


5 安装 PyTorch

Get Started

# 安装适配 CUDA 12.9 的 PyTorch (目前 PyTorch 最高支持到 CUDA 12.9)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu129

  • 预期输出 (示例)
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu129
Looking in indexes: https://download.pytorch.org/whl/cu129
Requirement already satisfied: torch in /home/workbench/anaconda3/lib/python3.12/site-packages (2.8.0.dev20250610+cu128)
Requirement already satisfied: torchvision in /home/workbench/anaconda3/lib/python3.12/site-packages (0.23.0.dev20250610+cu128)
Requirement already satisfied: filelock in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (3.13.1)
Requirement already satisfied: typing-extensions>=4.10.0 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (4.11.0)
Requirement already satisfied: setuptools in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (75.1.0)
Requirement already satisfied: sympy>=1.13.3 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (1.14.0)
Requirement already satisfied: networkx in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (3.3)
Requirement already satisfied: jinja2 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (3.1.4)
Requirement already satisfied: fsspec in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (2024.6.1)
Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.8.93 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.8.93)
Requirement already satisfied: nvidia-cuda-runtime-cu12==12.8.90 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.8.90)
Requirement already satisfied: nvidia-cuda-cupti-cu12==12.8.90 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.8.90)
Requirement already satisfied: nvidia-cudnn-cu12==9.8.0.87 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (9.8.0.87)
Requirement already satisfied: nvidia-cublas-cu12==12.8.4.1 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.8.4.1)
Requirement already satisfied: nvidia-cufft-cu12==11.3.3.83 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (11.3.3.83)
Requirement already satisfied: nvidia-curand-cu12==10.3.9.90 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (10.3.9.90)
Requirement already satisfied: nvidia-cusolver-cu12==11.7.3.90 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (11.7.3.90)
Requirement already satisfied: nvidia-cusparse-cu12==12.5.8.93 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.5.8.93)
Requirement already satisfied: nvidia-cusparselt-cu12==0.7.1 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (0.7.1)
Requirement already satisfied: nvidia-nccl-cu12==2.26.5 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (2.26.5)
Requirement already satisfied: nvidia-nvshmem-cu12==3.2.5 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (3.2.5)
Requirement already satisfied: nvidia-nvtx-cu12==12.8.90 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.8.90)
Requirement already satisfied: nvidia-nvjitlink-cu12==12.8.93 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (12.8.93)
Requirement already satisfied: nvidia-cufile-cu12==1.13.1.3 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (1.13.1.3)
Requirement already satisfied: pytorch-triton==3.3.1+gitc8757738 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torch) (3.3.1+gitc8757738)
Requirement already satisfied: numpy in /home/workbench/anaconda3/lib/python3.12/site-packages (from torchvision) (1.26.4)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /home/workbench/anaconda3/lib/python3.12/site-packages (from torchvision) (10.4.0)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/workbench/anaconda3/lib/python3.12/site-packages (from sympy>=1.13.3->torch) (1.3.0)
Requirement already satisfied: MarkupSafe>=2.0 in /home/workbench/anaconda3/lib/python3.12/site-packages (from jinja2->torch) (2.1.3)


6 一键验证

6.1 宿主 Windows 驱动检测(佐证兼容性)

先在 Windows 终端执行 nvidia-smi,确认驱动与 CUDA 支持情况(实际输出):

C:\Users\love>nvidia-smi
Sat Aug 30 21:22:56 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 581.08                 Driver Version: 581.08         CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3090      WDDM  |   00000000:01:00.0 Off |                  N/A |
|  0%   44C    P8             21W /  350W |    7107MiB /  24576MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

  • 关键结论Driver Version: 581.08 对应 CUDA Version: 13.0,证明驱动原生支持 CUDA 13.0。

6.2 WSL 内全链路验证

python - <<'PY'
import torch, subprocess
# 1. 验证 PyTorch 版本
print("1. PyTorch 版本 :", torch.__version__)
# 2. 验证 PyTorch 关联的 CUDA 版本(预期 < 13.0)
print("2. PyTorch 关联 CUDA 版本 :", torch.version.cuda)
# 3. 验证 cuDNN 版本
print("3. cuDNN 版本 :", torch.backends.cudnn.version())
# 4. 验证 GPU 识别
print("4. 识别到的 GPU :", torch.cuda.get_device_name(0))
# 5. 验证 nvcc 编译器版本(预期 < 13.0)
print("5. nvcc 编译器版本 :", subprocess.check_output(["nvcc","--version"]).decode().splitlines()[3])
# 6. 验证 GPU 计算可用性
print("\n6. GPU 张量计算验证:")
x = torch.randn(3,3, device='cuda')
y = torch.randn(3,3, device='cuda')
print("张量 X + Y:\n", x + y)
PY

或进入 Python 环境执行以下脚本:

import torch  # 导入 PyTorch 库
 
print("PyTorch 版本:", torch.__version__)  # 打印 PyTorch 的版本号
 
# 检查 CUDA 是否可用,并设置设备("cuda:0" 或 "cpu")
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print("设备:", device)  # 打印当前使用的设备
print("CUDA 可用:", torch.cuda.is_available())  # 打印 CUDA 是否可用
print("cuDNN 已启用:", torch.backends.cudnn.enabled)  # 打印 cuDNN 是否已启用
 
# 打印 PyTorch 支持的 CUDA 和 cuDNN 版本
print("支持的 CUDA 版本:", torch.version.cuda)
print("cuDNN 版本:", torch.backends.cudnn.version())
 
# 创建两个随机张量(默认在 CPU 上)
x = torch.rand(5, 3)
y = torch.rand(5, 3)
 
# 将张量移动到指定设备(CPU 或 GPU)
x = x.to(device)
y = y.to(device)
 
# 对张量进行逐元素相加
z = x + y
 
# 打印结果
print("张量 z 的值:")
print(z)  # 输出张量 z 的内容

  • 预期输出(全链路适配 CUDA 13.0):
(base) workbench@AI:/mnt/f/PythonProjects/SkyReels-V2$ python - <<'PY'
import torch, subprocess
# 1. 验证 PyTorch 版本
print("1. PyTorch 版本 :", torch.__version__)
# 2. 验证 PyTorch 关联的 CUDA 版本(预期 < 13.0)
print("2. PyTorch 关联 CUDA 版本 :", torch.version.cuda)
# 3. 验证 cuDNN 版本
print("3. cuDNN 版本 :", torch.backends.cudnn.version())
# 4. 验证 GPU 识别
print("4. 识别到的 GPU :", torch.cuda.get_device_name(0))
# 5. 验证 nvcc 编译器版本(预期 < 13.0)
print("5. nvcc 编译器版本 :", subprocess.check_output(["nvcc","--version"]).decode().splitlines()[3])
# 6. 验证 GPU 计算可用性
print("\n6. GPU 张量计算验证:")
x = torch.randn(3,3, device='cuda')
y = torch.randn(3,3, device='cuda')
print("张量 X + Y:\n", x + y)
PY
1. PyTorch 版本 : 2.8.0.dev20250610+cu128
2. PyTorch 关联 CUDA 版本 : 12.8
3. cuDNN 版本 : 90800
4. 识别到的 GPU : NVIDIA GeForce RTX 3090
5. nvcc 编译器版本 : Cuda compilation tools, release 13.0, V13.0.48

6. GPU 张量计算验证:
张量 X + Y:
 tensor([[-2.5236, -0.5435,  0.4742],
        [-1.2940, -1.5633, -0.1617],
        [ 0.9185,  0.5025, -0.4628]], device='cuda:0')

安装 PyTorch 之后,程式会自动降级适配 CUDA 和 cuDNN ,只要不超过最高支持的 CUDA 版本即可。



7 FAQ(修正驱动与 CUDA 兼容性问题)

问题 修正后答案
Workbench 是否自带 Anaconda? ,需手动安装
驱动 581.08 支持 CUDA 13.0 吗? ,通过 nvidia-smi 检测确认驱动原生支持 CUDA 13.0
PyTorch 应选择哪个 CUDA 版本? cu129 稳定版,目前仅支持到 CUDA 12.9
CUDA 13.0 能否实际生效? ,驱动与工具包版本匹配,可正常用于模型训练 / 推理

至此,基于 NVIDIA 驱动 581.08 的兼容性,已在 WSL-NVIDIA-Workbench 中完成 Anaconda、CUDA 13.0、cuDNN 9.12 及 PyTorch 的全链路适配安装,无版本妥协,可直接用于深度学习开发。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐