卸载 python 软件包后 pip 损坏

卸载 python 软件包后 pip 损坏

我卸载了 ubuntu 中的一些 python 包sudo pip uninstall packagename,之后我的 pip 就损坏了。当我这样做时,pip -V它显示这个

   from pip._internal.download import PipSession
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/download.py", line 15, in <module>
    from pip._vendor import requests, six, urllib3
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 97, 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/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in <module>
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

为了解决这个问题,我做的第一件事就是重新安装 pip 本身,所以我做了

sudo apt remove python-pip --purge
sudo apt install python-pip

pip -V给出了同样的错误。因此,我再次完全删除了 pip 而没有重新安装sudo apt remove python-pip --purge; sudo apt autoremove

现在我已经从我的系统中完全清除了 pip,但是即使这样做了之后,pip -V我仍然收到同样的错误?

答案1

查看所描述的错误,这看起来像是PyOpenSSLpython 包的问题。请按照以下步骤解决此问题(请确保从提示符运行命令sudo):

  • cd /usr/lib/python2.7/dist-packages/
  • rm -rf OpenSSL
  • rm -rf /home/<Your Username>/.local/lib/python2.7/site-packages/OpenSSL
  • pip install pyOpenSSL

如果这不起作用,请运行以下命令(请确保和python3pip3安装在您的机器上):

  • sudo pip3 install --upgrade pyOpenSSL

相关内容