1)创建并激活环境

conda create -n DOT1 python==3.9
conda activate DOT1

2)方法1:命令行安装torch

① 查看cuda版本【12.6】

nvidia-smi        # 查看电脑支持的cuda版本

nvcc -V        # 查看安装的cuda版本

② 去pytorch官网找命令

pytorch官网PyTorch

③ 直接输入图中命令:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

3)方法2:本地安装

① 输入命令

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

② 得到下图,可以看出,卡在了这一步。

点击图中网站:

③ 点击另存为:

随便找一个地方。我的存储路径是:

D:/03_temporary/

④ 在命令行下载

cd d:/03_temporary/
pip install torch-2.6.0+cu126-cp39-cp39-win_amd64.whl 

⑤ 安装torchvision 和 torchaudio

(没有tizi也可以直接安装)

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

4)检查是否成功

查看gpu版本的torch是否可用

python
import torch
print(torch.__version__)
print(torch.cuda.is_available())

输出如下图:说明可用。

[附录] 命令汇总

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
​
cd d:/03_temporary/
pip install torch-2.6.0+cu126-cp39-cp39-win_amd64.whl 
​
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
​
python
import torch
print(torch.__version__)
print(torch.cuda.is_available())

补充 

补充1:若要安装以前的老版本,同理:

官网在此:

以前的 PyTorch 版本 |PyTorch 插件

补充2:其它参考网站:

保姆级下载安装GPU(CUDA)版本PyTorch_cuda12.2对应的pytorch版本-CSDN博客

CUDA11.3以及PyTorch-GPU版本安装_cuda11.3对应的pytorch-CSDN博客

更多推荐