使用pip安装任何模块时出错,但easy_install有效

时间:2015-04-24 14:18:39

标签: python sockets pyopenssl

每当我尝试使用pip安装任何模块时都会出现此错误,但easy_install工作正常。我的Ubuntu 12.04机器中没有配置代理。 以前它工作正常,只是知道,它是如何突然停止工作的。

这是我在运行sudo pip install <any_package_name>时遇到的错误:

Exception:
Traceback (most recent call last):
  File "/tmp/tmpOA61D3/pip.zip/pip/basecommand.py", line 246, in main
    status = self.run(options, args)
  File "/tmp/tmpOA61D3/pip.zip/pip/commands/install.py", line 342, in run
    requirement_set.prepare_files(finder)
  File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 345, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 290, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 415, in _prepare_file
    req_to_install, finder)
  File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 376, in _check_skip_installed
    finder.find_requirement(req_to_install, self.upgrade)
  File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 425, in find_requirement
    all_versions = self._find_all_versions(req.name)
  File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 349, in _find_all_versions
    index_locations = self._get_index_urls_locations(project_name)
  File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 323, in _get_index_urls_locations
    page = self._get_page(main_index_url)
  File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 789, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 878, in get_page
    "Cache-Control": "max-age=600",
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/sessions.py", line 476, in get
    return self.request('GET', url, **kwargs)
  File "/tmp/tmpOA61D3/pip.zip/pip/download.py", line 367, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/sessions.py", line 464, in request
    resp = self.send(prep, **send_kwargs)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 762, in _validate_conn
    conn.connect()
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/tmp/tmpOA61D3/pip.zip/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 296, in ssl_wrap_socket
    cnx.set_tlsext_host_name(server_hostname)
AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

1 个答案:

答案 0 :(得分:7)

我找到了一个潜在的解决方案here。这是相关的引用:

“发生这种情况是因为Ubuntu 12.04(这是我服务器的操作系统)的旧pyOpenSSL库不接受属性'set_tlsext_host_name'。 要解决此问题,您需要添加依赖pyOpenSSL&gt; = 0.13。 在Ubuntu上进行更新pyOpenSSL使用pip,您还需要安装libffi-dev并按python-openssl删除apt。“

$ sudo apt-get purge python-openssl
$ sudo apt-get install libffi-dev
$ sudo pip install pyOpenSSL

如果不清楚或者它对你不起作用,请告诉我。