pip换清华源安装cuda版pytorch

有时候服务器只能访问大陆的网站,因此下载 cuda(gpu) 版的 pytorch非常慢。简单的方法是更换镜像源,网上的方法比较乱,实际上换源后直接安装即可。这里使用清华源。

设置全局 pip 源:

pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

检查全局 pip 源:

pip config list
# global.index-url='https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple'

安装:

pip install torch==2.5.1

或者临时使用镜像源:

pip install torch==2.5.1 -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

检查是否安装成功:

import torch
torch.cuda.is_available()
# True
torch.cuda.device_count()
# 10
torch.cuda.get_device_name(3)
# 'NVIDIA L20'
posted @ 2025-02-14 09:57  片刻的自由  阅读(4249)  评论(0)    收藏  举报