前提是Anaconda已经安装好,(Anaconda下载及安装教程:https://mp.csdn.net/postedit/89186513)
win7环境下用 Anaconda安装PyTorch步骤:
①左键单击电脑左下角的“开始”>>“所有程序”>>“Anaconda3”>>“Anaconda Prompt”
②在弹出的黑框中输入下列代码回车等待(这里很可能会出错,如果出错请先跳到第④步):
conda install pytorch-cpu torchvision-cpu -c pytorch
③验证:
在命令行输入:python>>
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
若输出以下张量则成功(随机生成的张量,里面数字不一样没关系,重要的是能输出一个张量了):
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
④补充:因为这个anaconda的源在国内下载会非常的慢,而且可能会报错误:CondaHTTPError:......
解决方案:在c盘Users(也就是用户)中用户名文件夹中的.condarc中添加指向清华源
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
- default
show_channel_urls: true
如果改成这样还是报错:CondaHTTPError:.....的话,那就去https://slproweb.com/products/Win32OpenSSL.html下载你电脑对应的openssl并安装,我64位的电脑下载了:win64 OpenSSL v1.1.1c ,安装好后再次重复①②步应该就好了。