- 修改源,添加 Anaconda Python 免费仓库
sudo gedit ~/.condarc
修改内容如下
channels:
1. defaults
show_channel_urls: true
default_channels:
2. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
3. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
4. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
清除索引缓存,保证用的是镜像站提供的索引
conda clean -i
2. 打开pytorch网站https://pytorch.org/get-started/locally/,选择自己需要的版本
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210217105504207.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0dyYWNleWluZw==,size_16,color_FFFFFF,t_70#pic_center)
执行下载命令
```bash
conda install pytorch torchvision torchaudio cudatoolkit=10.1 -c pytorch
等待出现以下内容完成安装
udatoolkit=10.1 -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: /
Warning: 2 possible package resolutions (only showing differing packages):
- https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/linux-64/linux-64::conda-4.9.2-py38h06a4308_0
- defaults/linux-64::conda-4.9.2-py38h06a4308done
## Package Plan ##
environment location: /home/xxy/anaconda3
added / updated specs:
- cudatoolkit=10.1
- pytorch
- torchaudio
- torchvision
The following packages will be downloaded:
package | build
---------------------------|-----------------
numpy-1.19.2 | py38h54aff64_0 22 KB defaults
pytorch-1.7.1 |py3.8_cuda10.1.243_cudnn7.6.3_0 553.1 MB pytorch
torchvision-0.8.2 | py38_cu101 17.8 MB pytorch
typing_extensions-3.7.4.3 | pyha847dfd_0 25 KB defaults
------------------------------------------------------------
Total: 570.9 MB
The following NEW packages will be INSTALLED:
blas anaconda/pkgs/main/linux-64::blas-1.0-mkl
cudatoolkit anaconda/pkgs/main/linux-64::cudatoolkit-10.1.243-h6bb024c_0
intel-openmp anaconda/pkgs/main/linux-64::intel-openmp-2020.2-254
libuv anaconda/pkgs/main/linux-64::libuv-1.40.0-h7b6447c_0
mkl anaconda/pkgs/main/linux-64::mkl-2020.2-256
mkl-service anaconda/pkgs/main/linux-64::mkl-service-2.3.0-py38he904b0f_0
mkl_fft anaconda/pkgs/main/linux-64::mkl_fft-1.2.0-py38h23d657b_0
mkl_random anaconda/pkgs/main/linux-64::mkl_random-1.1.1-py38h0573a6f_0
ninja anaconda/pkgs/main/linux-64::ninja-1.10.2-py38hff7bd54_0
numpy anaconda/pkgs/main/linux-64::numpy-1.19.2-py38h54aff64_0
numpy-base anaconda/pkgs/main/linux-64::numpy-base-1.19.2-py38hfa32c7d_0
pytorch pytorch/linux-64::pytorch-1.7.1-py3.8_cuda10.1.243_cudnn7.6.3_0
torchaudio pytorch/linux-64::torchaudio-0.7.2-py38
torchvision pytorch/linux-64::torchvision-0.8.2-py38_cu101
typing_extensions anaconda/pkgs/main/noarch::typing_extensions-3.7.4.3-pyha847dfd_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
typing_extensions-3. | 25 KB | ######################################################################################################################################################################## | 100%
pytorch-1.7.1 | 553.1 MB | ######################################################################################################################################################################## | 100%
torchvision-0.8.2 | 17.8 MB | ######################################################################################################################################################################## | 100%
numpy-1.19.2 | 22 KB | ######################################################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
测试是否安装成功
import torch
import torchvision
x = torch.rand(5, 3)
print(x)
torch.cuda.is_available()
显示如下
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision
>>> x = torch.rand(5, 3)
>>> print(x)
tensor([[0.6433, 0.1002, 0.7137],
[0.5428, 0.3415, 0.5244],
[0.7444, 0.3307, 0.8274],
[0.5290, 0.0789, 0.3824],
[0.1561, 0.3142, 0.7884]])
>>> torch.cuda.is_available()
True
>>>