Windows下安装pytorch框架:
提示:是在Anaconda下安装,如果没有,可自行安装:
打开pytorch官网:`pytorch.org
官网一般会根据电脑的配置自行选择好,我采用的是conda安装方式,请注意划线行命令是不是这种格式(版本号可以跟图中不一样!),如果不是可以在“Compute Platform”选择换一个CUDA型号。待会儿会用到这行命令。
打开Anaconda Prompt
提示:在开始目录下Anaconda下可以找到
我们一般就是将这行命令复制下来,然后在prompt中运行一下就行,但是由于pytorch本身源的问题,这样下载下来非常慢!甚至安装超时直接失败。
所以我们采用第二种方法:使用镜像文件
添加清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
将上面的代码一行一行复制下来,在prompt中回车运行下。
使用conda config --show
可以看到自己添加的镜像源
如果不想要了,也可以使用conda config --remove channels +你想要移除的镜像源网址
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
开启安装:
使用之前的那个命令安装,注意要去掉“-c pytorch”
conda install pytorch torchvision torchaudio cudatoolkit=11.3
等待一会“solving”,然后会列举要安装的包,敲“y“继续安装
大概会下载几个G的文件,如果你的Anaconda是安装在C盘的话,下载的文件会出现在你电脑的这个位置C:\Users\35159\Anaconda3\pkgs
测试是否安装成功:
在prompt上使用以下测试代码:
python
import torch
torch.__version__#注意是两个下划线
torch.cuda.is_available()
torch.cuda.current_device()
torch.cuda.device(0)
torch.cuda.device_count
torch.cuda.device_count()
torch.cuda.device_name(0)
torch.cuda.get_device_name(0)
也可以只测“torch.version”和“torch.cuda.is_available()”这两条语句
测试结果如上图所示即安装成功!
参考blog:
1.https://blog.csdn.net/qq_44722174/article/details/104800082
2.https://www.cnblogs.com/zhouzhiyao/p/11784055.html