-
Create a virtual environment
conda create -n pytorch python=3.8
conda env list
conda activate pytorch
-
Go to the official the corresponding installation command:
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
However, the download is a bit slow. I first downloaded Torch with Motrix : https://download.pytorch.org/whl/cu101/torch-1.7.0%2Bcu101-cp38-cp38-linux_x86_64 .whl
and then install torch first (you need to switch to the directory where you downloaded torch):pip install torch-1.7.0+cu101-cp38-cp38-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/
Finally, use this command to download the rest of the library: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
-
Test whether the installation is complete:
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 installs Pytorch1.7.0 GPU version torchvision=0.8.1 (CUDA and CUDNN have been installed)
Guess you like
Origin blog.csdn.net/qq_42887760/article/details/126908666
Ranking