前言
用pip安装tensorflow等软件包的时候经常会出现,安装过慢或者安装了98%还卡死报错的问题,只是因为pip默认是从外网下载软件包,所以很容易出现连不上或者连接速度慢的问题,在这种情况下最好的解决方法就是换国内镜像源安装。
1)安装过慢
2)超时报错:ReadTimeoutError
解决方法1
换国内镜像源:
将原来的命令pip install tensorflow-gpu
换成pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu
,这样就会从清华的镜像源下载最新版本的tensorflow-gpu的whl文件并安装。如果需要安装固定的版本,比如1.5.0,还可将命令改为pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.5.0
,这样的话pip安装一定会快的飞起。
国内镜像源
有时候某些包可能在清华的镜像源没有想要的版本(貌似19年开始不更新),这时候可以换下面其他国内镜像源安装。
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
解决方法2
如果用了上面方法1还报超时错误,那就用下面的方法:
设置超时时间,防止下载时间超过超时时间:
如pip install --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.5.0
参考
[1] 解决pip安装时速度慢的问题
[2] 让PIP源使用国内镜像,提升下载速度和安装成功率。
[3] python 安装第三方库,超时报错–Read timed out.
码字不易,如果您觉得有帮助,欢迎点赞和收藏~~