栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Torch安装报错pip.

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Torch安装报错pip.

1.问题

使用命令安装torch:

pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

这时候报错:

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='download.pytorch.org', port=443): Read timed out.
2.分析问题产生原因

(1)大概率是网络问题,也就是阿里云的镜像源提供的网速不足以支撑2个G的torch安装
(2)也许可能版本不匹配,但这一问题我在官方网站复制的命令:torch安装官网提供的命令,应该是问题不大的。

3.解决办法

切换镜像源:
豆瓣:http://pypi.douban.com/simple/
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
山东理工大学:http://pypi.sdutlinux.org/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学:http://pypi.hustunique.com/
因此命令可以改为:

```powershell
pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple

或者一个一个镜像试过去,总会有效果的!

4.大牛提供的方法

如果你的网速一直很拉闸,上面的方法依然解决不了,那这时可以使用如下的解决方案:

pip --default-timeout=1688 install 库名称 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 

那在这里可以分别用该方法安装torch和torchvision
也就是使用命令:

pip3 --default-timeout=1688 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

这里的--default-timeout=1688其实意思就是让其检测延迟的时间变长,以防止因为你的网络问题而直接报错。以上有可能也会报错,因为你所选用的镜像源是不存在这样的包的,这时候可以切换镜像源。如下所示:

还没有使用这个技巧之前,前面好多次都是安装在了600多M就因为网络问题停止安装了,有一次甚至都2000多M了以为要成功的时候GG了,真的气哭了。

5.安装成果展示


虽然安装成功了,但新的风暴又产生了:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
projectq 0.7.0 requires matplotlib>=2.2.3, which is not installed.
projectq 0.7.0 requires networkx>=2, which is not installed.
projectq 0.7.0 requires requests, which is not installed.
projectq 0.7.0 requires scipy, which is not installed.

不过这个风暴,直接使用安装matplotlib包,其他几个包的命令也如下所示:

pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple

这样的代码块,将报错的几个包全部安装成功就了!
最后,在命令行下输入python:

(torchlearning) C:WINDOWSsystem32>python

然后进入python操作行输入一下代码:

import torch
x = torch.rand(5, 3)
print(x)


出现以上结果就表示torch终于TM的安装成功了!!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/444788.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号