我在linux上安装了pip,pip list
命令正常工作。但是当使用pip install
命令时,它会收到以下错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/commands/install.py", line 339, in run
requirement_set.prepare_files(finder)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/req/req_set.py", line 333, in prepare_files
upgrade=self.upgrade,
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/index.py", line 305, in find_requirement
page = self._get_page(main_index_url, req)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/index.py", line 783, in _get_page
return HTMLPage.get_page(link, req, session=self.session)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/index.py", line 872, in get_page
"Cache-Control": "max-age=600",
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/sessions.py", line 473, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/download.py", line 365, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/sessions.py", line 461, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/cachecontrol/adapter.py", line 43, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/adapters.py", line 370, in send
timeout=timeout
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 518, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 322, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 727, in _validate_conn
conn.connect()
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
ssl_version=resolved_ssl_version)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.7-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py", line 254, in ssl_wrap_socket
return context.wrap_socket(sock)
File "/usr/local/lib/python2.7/ssl.py", line 350, in wrap_socket
_context=self)
File "/usr/local/lib/python2.7/ssl.py", line 537, in __init__
raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
我该如何解决这个问题?
答案 0 :(得分:19)
pip 6.1.0已经发布,解决了这个问题。您可以使用以下方式升级:
pip --trusted-host pypi.python.org install -U pip
自我升级。
原始答案:
这是由Python 2.7.9的变化引起的,urllib3
需要考虑这一变化。有关该项目,请参阅issue #543。您的OpenSSL库不支持SNI,这意味着urllib3
不会将主机名传递给SSL套接字包装器,但是Python 2.7.9期望主机名无论如何都会被传递用于不同的目的。
urllib3
由requests
间接使用(请参阅requests
issue 2435),pip
正在使用<{1}}。
我打开了ticket to track this from pip
's perspective。
项目维护人员已经修复了基础问题,等待新版本。如果您不耐烦,可以安装pip
的当前开发版本:
pip install --trusted-host=github.com -U https://github.com/pypa/pip/archive/develop.zip
这将安装pip-6.1.0.dev0,当6.1.0完全发布时,您可以使用pip install -U pip
再次升级以从PyPI获得最终版本。
答案 1 :(得分:15)
我遇到同样的问题,发现在我的情况下可以避免(pip 6.0.8)如下
pip --trusted-host pypi.python.org install <thing>
答案 2 :(得分:1)
与urllib3有关。 您可以使用 urllib3 版本 1.25.8 解决它。 手动下载该版本的 urllib3 并安装。
即使你安装了 thia 版本,pip 仍然会使用它自己的版本。所以你必须删除它并替换它。
通常,安装的模块在 PythonXX/Lib/site-packages 上
删除PythonXX/Lib/site-packages/pip/_vendor中的urllib3
将“PythonXX/Lib/site-packages/urllib3”移动到“PythonXX/Lib/site-packages/pip/_vendor”。