1.直接到NVIDA官网下载相应的驱动,然后安装官方驱动 | NVIDIA
2.下载相应版本cuda,并安装,安装时不安装驱动
3.conda install pytorch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 pytorch-cuda=12.1 -c pytorch -c nvidia 安装pytorch。
安装之前先部署环境:conda create -n pytorch python=3.11
因为安装的pytorch版本是2.1.0。
注意:这里pytorch-cuda=12.1
但是:
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jun_13_19:16:58_PDT_2023
Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0
这里显示12.2不影响。
验证:
(pytorch) wawayu@wawayu:~$ python
Python 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.1.0
>>> torch.cuda.is_available()
True