pip install下载缓慢的解决方法

在安装python库,在网络不好的情况会遇到

raise ReadTimeoutError(self._pool, None, ‘Read timed out.’)
ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out.

解决办法1:延长timeout时间

raise ReadTimeoutError(self._pool, None, ‘Read timed out.’)ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out. pip --default-timeout=100 install Package

将Package替换你所需要的库就行

解决办法2:换源,将pip源更换到国内镜像

#例如安装scipy时使用豆瓣的源
pip install --index-url https://pypi.douban.com/simple scipy
#使用清华大学的源 p
p install -i https://pypi.tuna.tsinghua.edu.cn/simple –upgrade tensorflow-gpu

将pip源更换到国内镜像
用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。
其中,比较常用的国内镜像包括:

(1)阿里云 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
(5)华中科技大学http://pypi.hustunique.com/

注意:新版ubuntu要求使用https源。

设置方法:(以清华镜像为例,其它镜像同理)
(1)临时使用:
可以在使用pip的时候,加上参数-i和镜像地址(如
https://pypi.tuna.tsinghua.edu.cn/simple),
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。

(2)永久修改,一劳永逸:
(a)Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

你可能感兴趣的:(成长笔记)