安装python下的requests包出错

环境:

mac os: 10.13.6

python:2.7.10

virtualenv

$ pip install requests

Collecting requests

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x109cfa510>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)': /packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl

  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x109cfa750>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)': /packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl

  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x109cfa890>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)': /packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl

  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x109cfa910>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)': /packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl

  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x109cfa9d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)': /packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl

Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (Caused by NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x109cfaad0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

 解决,有可能是网络问题造成。

$ pip install requests -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

Looking in indexes: http://pypi.douban.com/simple/

Collecting requests

  Downloading http://pypi.doubanio.com/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)

    100% |████████████████████████████████| 92kB 1.3MB/s 

Collecting certifi>=2017.4.17 (from requests)

  Downloading http://pypi.doubanio.com/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl (147kB)

    100% |████████████████████████████████| 153kB 2.1MB/s 

Collecting chardet<3.1.0,>=3.0.2 (from requests)

  Downloading http://pypi.doubanio.com/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)

    100% |████████████████████████████████| 143kB 5.6MB/s 

Requirement already satisfied: urllib3<1.24,>=1.21.1 in ./.virtualenvs/python_2/lib/python2.7/site-packages (from requests) (1.23)

Collecting idna<2.8,>=2.5 (from requests)

  Downloading http://pypi.doubanio.com/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)

    100% |████████████████████████████████| 61kB 5.5MB/s 

Installing collected packages: certifi, chardet, idna, requests

Successfully installed certifi-2018.8.24 chardet-3.0.4 idna-2.7 requests-2.19.1

原文地址:https://www.cnblogs.com/herosoft/p/9741748.html