本文已参与「新人创作礼」活动,一起开启掘金创作之路。
最近新电脑安装Pytorch时,发现……
如果挂代理吧,就报标题那种错误
ValueError('check_hostname requires server_hostname')
不挂吧,国内镜像源现在一个比一个慢,甚至是没有镜像:
ERROR: Could not find a version that satisfies the requirement torch==1.9.1+cu111
网上有说 ValueError('check_hostname requires server_hostname') 是urllib3版本过高的问题,降低下版本就好亲测无效……
于是换一个思路,先去download.pytorch.org/whl/torch_s…把需要的包下载下来。 我所安装版本的pytorch 的pip命令是:(其实以前都挂代理用conda装,不过conda的命令版本信息不明显)
pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
所以对应的包是:
torch-1.9.1+cu111-cp39-cp39-win_amd64.whl torchvision-0.10.1+cu111-cp39-cp39-win_amd64.whl torchaudio-0.9.1-cp39-cp39-win_amd64.whl
都下载下来之后,用下面的命令逐个安装
pip install 路径/**.whl
注:再此之前我参考github.com/pytorch/pyt…安装过依赖包, 如果上面的方法没有自动安装依赖包的话,也执行一下最好。
conda install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
最后附上测试pytorch是否成功安装的测试代码:
import torch # 如正常则静默
a = torch.Tensor([1.]) # 如正常则静默
a.cuda() # 如正常则返回"tensor([ 1.], device='cuda:0')"
from torch.backends import cudnn # 如正常则静默
cudnn.is_acceptable(a.cuda()) # 如正常则返回 "True"