首先参考这里https://stackoverflow.com/questions/49768770/not-able-to-install-python-packages-ssl-tlsv1-alert-protocol-version
首先你要pip安装某一个工具的时候遇到下面类似的错误
Traceback (most recent call last):
File "/Users/finaris/PycharmProjects/test/test/test.py", line 14, in
c.request('GET', '/api/config/v1/aaa/users', headers=headers)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1151, in _send_request
self.endheaders(body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1102, in endheaders
self._send_output(message_body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1260, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 377, in wrap_socket
_context=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 752, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 988, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 633, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)
也许大多数人直接执行下面的代码就可以解决问题了
curl https://bootstrap.pypa.io/get-pip.py | python
但是我又遇到了其他问题,类似下面的
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
这时候可以先吧https://bootstrap.pypa.io/get-pip.py这个网页的py文件先下载下来,然后执行
//先到下载的目录
cd /Users/ccMac/Downloads
//执行
python get-pip.py
假如提示你:
Collecting pip
Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
29% |█████████▌ | 389kB 4.1kB/s eta 0:03:46
Exception:
.....
那么就把这个文件下载下来,自己安装
https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
下载下来后,然后安装
pip install /Users/ccMac/Downloads/pip-10.0.1-py2.py3-none-any.whl
假如提示你下面的错误:
....
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'
这样执行:
sudo pip install /Users/liumengkai/Downloads/pip-10.0.1-py2.py3-none-any.whl
finally:
Successfully installed pip-10.0.1
pip -V
pip 10.0.1 from /Library/Python/2.7/site-packages/pip (python 2.7)