0

I uninstalled some python packages in ubuntu using sudo pip uninstall packagename and after that my pip got corrupted. When I do pip -V its showing this

   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'

The first thing I did to solve this problem is to reinstall pip itself so I did

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

But pip -V gives the same error. So I then again completely removed pip without reinstalling sudo apt remove python-pip --purge; sudo apt autoremove.

Now I have completely purged pip from my system but even after this when I did pip -V I am getting same error?

Eka
  • 2,967
  • 12
  • 38
  • 60

1 Answers1

1

On taking a look at the error described, this looks like an issue with the PyOpenSSL python package. Please follow these steps for resolving this issue (please make sure that the commands are run from a sudo prompt):

  • 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

If that doesn't work out, run the following (please make sure that the python3 and pip3 are installed in your machine):

  • sudo pip3 install --upgrade pyOpenSSL