-
创建虚拟环境
conda create -n pytorch python=3.8
conda env list
conda activate pytorch
-
去官网下载对应的安装命令:
pip install torch==1.7.0+cu101 torchvision==0.8.1+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
不过,下载的有点慢,我是先用Motrix下载Torch:https://download.pytorch.org/whl/cu101/torch-1.7.0%2Bcu101-cp38-cp38-linux_x86_64.whl
然后先安装torch(需要切换到下载torch的目录下):pip install torch-1.7.0+cu101-cp38-cp38-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/
最后用该命令进行下载其余的库:pip install torch==1.7.0+cu101 torchvision==0.8.1+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
-
测试是否安装完成:
import torch import torchvision if __name__ == "__main__": print(torch.__version__) # 查看torch当前版本号 print(torchvision.__version__) # 查看CUDA版本号: print(torch.version.cuda) # 编译当前版本的torch使用的cuda版本号 # 测试Cudnn是否安装成功 from torch.backends import cudnn print(cudnn.is_available()) # 是否GPU可用 print(torch.cuda.is_available()) # 查看当前cuda是否可用于当前版本的Torch,如果输出True,则表示可用
Ubuntu20.04安装 Pytorch1.7.0 GPU版 torchvision=0.8.1 (已装好CUDA和CUDNN)
于 2022-09-17 18:01:26 首次发布