【问题标题】:Pip install/upgrade error, will not install or upgrade anything, odd tracebackPip 安装/升级错误,不会安装或升级任何东西,奇怪的回溯
【发布时间】:2015-10-04 18:46:47
【问题描述】:

Python Version=2.6.6

好的,所以这个让我难住了。

首先,这是我尝试安装某些东西时的回溯。在这种情况下,我跑了:pip install requests 作为根。注意:我知道这是 pip 版本7.0.3。最新版本的 pip 会出现相同的回溯。

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/commands/install.py", line 291, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/wheel.py", line 705, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_set.py", line 317, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_set.py", line 304, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_set.py", line 439, in _prepare_file
    req_to_install.populate_link(finder, self.upgrade)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_install.py", line 244, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 486, in find_requirement
    all_versions = self._find_all_versions(req.name)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 404, in _find_all_versions
    index_locations = self._get_index_urls_locations(project_name)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 378, in _get_index_urls_locations
    page = self._get_page(main_index_url)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 810, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 920, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/sessions.py", line 477, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/download.py", line 373, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
    conn.connect()
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 279, in ssl_wrap_socket
    cnx.set_tlsext_host_name(server_hostname)
AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

然后我使用pip uninstall pip卸载了pip,并确认鸡蛋和二进制文件已被删除。然后我使用easy_install pip 重新安装了它,但没有运气。我也再次尝试了这个,但使用了最新版本的 pip 和版本7.0.3。一样的。

另外,安装 get-pip.py 会给出这个回溯,这非常相似:

Traceback (most recent call last):
  File "/tmp/tmp0rv6P1/pip.zip/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/tmp/tmp0rv6P1/pip.zip/pip/commands/install.py", line 291, in run
    wb.build(autobuilding=True)
  File "/tmp/tmp0rv6P1/pip.zip/pip/wheel.py", line 705, in build
    self.requirement_set.prepare_files(self.finder)
  File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 317, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 304, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 387, in _prepare_file
    req_to_install, finder)
  File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 348, in _check_skip_installed
    finder.find_requirement(req_to_install, self.upgrade)
  File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 486, in find_requirement
    all_versions = self._find_all_versions(req.name)
  File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 404, in _find_all_versions
    index_locations = self._get_index_urls_locations(project_name)
  File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 378, in _get_index_urls_locations
    page = self._get_page(main_index_url)
  File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 810, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 920, in get_page
    "Cache-Control": "max-age=600",
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/sessions.py", line 477, in get
    return self.request('GET', url, **kwargs)
  File "/tmp/tmp0rv6P1/pip.zip/pip/download.py", line 373, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
    conn.connect()
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 279, in ssl_wrap_socket
    cnx.set_tlsext_host_name(server_hostname)
AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

真正让我感到困惑的是回溯的最后 4 行。在分析回溯后,我深入研究了 pip egg。

很明显,从回溯来看,错误来自ssl_wrap_socket 函数,该函数在connection.py 中调用。回溯说,ssl_wrap_socket 被调用是在{urlib3_path}/contrib/pyopenssl.py 中定义的,但是,在查看45-50connection.py 行时:

# connection.py
     from .util.ssl_ import (
         resolve_cert_reqs,
         resolve_ssl_version,
         ssl_wrap_socket,
         assert_fingerprint,
     )

ssl_wrap_socket 应该从不包含违规代码行的{urllib3_path}/util/ssl_.py 导入,但根据不是正在发生的情况的回溯。

我不知道发生了什么,但假设这是我不知道的一些关于 python 的微妙之处。如果有人有任何线索,请告诉我。

编辑:新的发展!

在从 github 偶然发现 this bit of the requests code 时,似乎请求库实际上将 pyopenssl 注入到解释回溯的 urllib3 库中。但是我仍然不确定如何解决这个问题。

Edit2:解决方案!

原来 urllib3 库被注入了错误的 pyopenssl !在我发现请求将pyopenssl 注入urllib3 库后,我检查了pyopenssl.py 并找到了这个函数:

def inject_into_urllib3():
    'Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.'

    connection.ssl_wrap_socket = ssl_wrap_socket
    util.HAS_SNI = HAS_SNI

ssl_wrap_socketpyopenssl.py 中定义并依赖于OpenSSL.SSL

我跳到site-packages 文件夹中的pyOpenSSL-0.15.1-py2.6.egg,只是为了确保检查了版本,它是0.15.1。经过一番思考,我打开了解释器并运行了

>>> import OpenSSL.SSL as ssl
>>> ssl.__file__

这告诉我我在 lib64/python2.6/site-packages 中有一个被引用的 OpenSSL 目录,而不是 pyOpenSSL egg 中的 OpenSSL 目录,而且它只是版本 0.10!这当然是导致原始错误被抛出的原因。删除该目录后,Pip 似乎运行没有问题。

【问题讨论】:

  • 你试过用curl -s https://bootstrap.pypa.io/get-pip.py | sudo python安装pip吗?
  • 我做到了。我也从中添加了回溯。
  • 您使用的是 Ubuntu 12.04 或更早的操作系统吗?
  • 红帽企业 Linux 服务器 6.5 版(圣地亚哥)

标签: python import openssl dependencies pip


【解决方案1】:
easy_install http://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.12.tar.gz

执行以上行可能会解决您的问题。

CentOS 5.6 有一个upstream bug 与此问题相关。 还有一个workaround patch 用于修复它。如果上面的方法不起作用,你可以试试这个。

【讨论】:

  • 感谢您的帮助,但我最终找到了解决方案。
【解决方案2】:

我尝试了 devunt 的 easy_install 代码行,但没有成功。它拒绝访问一堆有冲突的 python 2.7 文件。我基本上对pip有同样的问题。我在 Mac OSX 上,卡在 pip 7.0.3 上,为了获得 scikit、numpy 和 scipy 之类的东西,我显然需要升级到 7.1.0。我在 Python 2.7.6 上,当我尝试下载 mysql-python 时遵循错误消息后,我被带到一个如图所示的错误消息并跟随它到源,这是由于 SSL 安全性导致系统不稳定的错误消息围绕https'(即Python 2.7.6)。我的错误信息是这样的:

You are using pip version 7.0.3, however version 7.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/Library/Python/2.7/site-packages/pip-7.0.3 py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90:              InsecurePlatformWarning: A true SSLContext object is not available. This prevents        urllib3 from configuring SSL appropriately and may cause certain SSL connections        to fail. For more information, see   https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Collecting pip
Using cached pip-7.1.0-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 7.0.3
Uninstalling pip-7.0.3:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.0.3-py2.7.egg/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.0.3-py2.7.egg/pip/commands/install.py", line 297, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.0.3-py2.7.egg/pip/req/req_set.py", line 616, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-7.0.3-py2.7.egg/pip/req/req_install.py", line 721, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-7.0.3-py2.7.egg/pip/req/req_uninstall.py", line 126, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-7.0.3-py2.7.egg/pip/utils/__init__.py", line 314, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
rmtree(src)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 247, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-        7.0.3-py2.7.egg/EGG-INFO/dependency_links.txt'

因此,据我了解,此错误是由 Python 2.7.6 上与 Mac 的 OS X 捆绑在一起的不兼容引起的。由于 Mac 上的 brew 是我过去用来升级 python 的,所以我使用了“brew update”,当 brew 更新时,我使用“brew install --upgrade python”升级了 python,完成后我检查了我的版本,如下所示如下:

John-Mulhalls-MacBook-Pro:Python_DataBase_Project jmulhall$ brew --version
0.9.5
John-Mulhalls-MacBook-Pro:Python_DataBase_Project jmulhall$ python --version
Python 2.7.10
John-Mulhalls-MacBook-Pro:Python_DataBase_Project jmulhall$ pip --version
pip 7.1.0 from /usr/local/lib/python2.7/site-packages (python 2.7)
John-Mulhalls-MacBook-Pro:Python_DataBase_Project jmulhall$ 

解决此错误的教训是将 python 升级到 2.7.9(我读到了影响 Pip 的先前版本中的错误)或更高版本。 Pip 将作为 Pip 7.1.0 与 Python 2.7.10 捆绑在一起。我成功安装了'brew install mysql-python' 当回到数据科学、决策树和 python 时,将开始安装 bumpy、scipy 和 scikit。希望这对兄弟有帮助!!..

【讨论】:

    猜你喜欢
    • 2018-09-10
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 2019-06-17
    相关资源
    最近更新 更多