本文是我的安装记录
首先创建一个python版本为3.9的虚拟环境
conda create -n pytorch python=3.9
查看本机的cuda版本
nvidia-smi
显示CUDA版本是12.5
激活环境
conda activate pytorch
进入官网pytorch,在主页选择,pip安装,CUDA11.8版本,结果速度非常慢,因为它使用了pytorch官方的镜像源 --index-url 后是下载镜像源。
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
将地址替换成
清华镜像
pip3 install torch torchvision torchaudio --index-url https://pypi.tuna.tsinghua.edu.cn/simple
下载速度快了很多,大概需要五分钟
如果您想要下载自己需要的版本点击Previous version of PyTorch
找到使用pip安装的命令,复制红色框里的内容,这是为了确定要安装的版本信息,通过下面的代码指定镜像源即可。
--index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您的pip已经配置了清华镜像源,可以直接复制红色框里的内容下载,不需要指定。
查看自己的pip镜像可以输入下面的命令。
pip config list