更新到 Ubuntu 18.04 LTS 后,我无法再使用大多数 Python 应用程序,包括 pip(安装或卸载)。我在命令行中收到以下错误:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module> load_entry_point('pip==10.0.1', 'console_scripts', 'pip')()
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 572, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2755, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2408, in load
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2414, in resolve
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 15, in <module>
from pip._vendor import html5lib, requests, six
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 86, in <module>
from pip._vendor.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/usr/local/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 105, in <module>
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
在 Google 上搜索错误后,似乎 pyopenssl 的版本已过期,但我尝试通过 TGZ 文件或通过 easy_install 手动下载 installpyopenssl18,但都没有成功。
我无法通过 pip 安装/卸载,因为我收到上述错误。有什么建议吗?我想避免重新安装 Python 甚至操作系统本身。
如果我在命令行中输入 python,它使用 Python 2.7.15rc1(默认,2018 年 4 月 15 日,21:51:34)
答案1
再次尝试手动安装 pyopenssl 18 后,我注意到它的安装路径为:/usr/local/lib/python2.7/dist-packages
因此我深入挖掘该目录并看到一个名为的文件夹:
OpenSSL
错误中引用了该文件夹。我重命名了此文件夹并重新安装了 pyopenssl,错误已清除。我访问 HTTPS 站点时没有遇到任何问题,所以这可能是 pyOpenSSL 替换的弃用模块?