python3 库(lib)下载超时下载慢报错问题更改pip源操作完美解决

python3 库(lib)下载超时下载慢报错问题更改pip源操作完美解决

D:\Program\Project\PyPro>pip install urllib2
Collecting urllib2
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/urllib2/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/urllib2/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/urllib2/
  ERROR: Could not find a version that satisfies the requirement urllib2 (from versions: none)
ERROR: No matching distribution found for urllib2

问题:下载lib库报timeout超时错误或者下载速度慢

上面报错是打算学习爬虫的时候,安装lib库报出的错误。由于是在家乡,用的广电的网络。很多国外的网站githu,stackflow等都访问不了。包括python下载库的官方网站 http://pypi.python.org。这个网站是pip安装的默认访问网址。一旦本地网络不好或者连接不上该网址,就会出现上面的timeout报错。
解决办法:将pip下载源地址转换为国内的镜像源。

  • 国内常用的镜像源有 :
    阿里云 http://mirrors.aliyun.com/pypi/simple/
    中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
    豆瓣(douban) http://pypi.douban.com/simple/
    清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
    中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

具体操作:

Linux】修改默认镜像源的操作编辑 vi ~/.pip/pip.conf

Windows】修改默认镜像源的方法:

  1. 在user目录中创建一个pip目录
    如:C:\Users\xx\pip,本人的电脑地址为C:\Users\Administrator\pip
    手动操作点击c盘,进入“用户”文件夹,进入“Administrator”文件夹,创建“pip”文件夹
  2. 使用notepad++等文本编辑工具在“pip”文件夹下新建文件pip.ini
    编辑文件pip.ini:
[global]
timeout = 6000
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
timeout = 6000

成功更改pip镜像源结果如下所示:

D:\Program\Project\PyPro>pip install pyserial
Looking in indexes: https://pypi.doubanio.com/simple/
Collecting pyserial
  Downloading https://pypi.doubanio.com/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl (193kB)
Installing collected packages: pyserial
Successfully installed pyserial-3.4
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

你可能感兴趣的:(python进阶)