Python "pip install " is failing with AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
Asked Answered
A

4

62

$ sudo pip install --upgrade pyOpenSSL

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, 
in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 
2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 
2355, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 
2361, in resolve
 module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
 py2.7.egg/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar  # noqa
 File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
 py2.7.egg/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/download.py", line 39, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
  py2.7.egg/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", 
line 
54, 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'

I am unable to Uninstall " pip uninstall pyopenssl "

Using pip gets me this error.

Thanks in advance.

Additional Details:

I am using

Distributor ID: Ubuntu Description: Ubuntu 15.10 Release: 15.10 Codename: wily

Arguable answered 19/7, 2017 at 10:52 Comment(2)
Seeing the same thing, I updated pip and now I am seeing the same error. I am on Ubuntu 16.04.02LTS Python 2.7.Prototype
Please, show your PYTHONPATH variable echo $PYTHONPATH.Fretwell
F
138

I ran into this issue as well. The solution proposed to run pip doesn't work because pip is broken too! I found this solved it for me:

sudo python -m easy_install --upgrade pyOpenSSL

This installed version 17.3.0 which was an upgrade to the (stock python-openssl on xenial) version ?0.15.1?. Note the massive change in version it could be they dropped the leading 0. in later versions.

Anyway, after that, pip and ansible started to work again.

Fbi answered 28/9, 2017 at 18:18 Comment(4)
Thanks, worked for me too. And this solution looks much more correct than deleting /usr/lib/python2.7/dist-packages/OpenSSL manually, as for me.Secondhand
Or for python3 use: sudo easy_install3 --upgrade pyOpenSSLFalkner
Very useful...!Icky
Worked on Mint 19.3 too.Figurate
P
108

I did the following which seemed to fix the error, not sure if it's the correct way, but it did fix the error on my machine:

I first backed up the directories below, recommend you do same.

rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-0.15.1.egg-info
sudo pip install pyopenssl

I couldn't uninstall it because every time I ran pip I got the same error you did: 'module' object has no attribute 'SSL_ST_INIT'.

After the above my pip now works and more importantly my ansible now works (which was broken by my previous updates).

Not sure if it will work on your system, and removing things out of band, like I did, is risky at best, so as a warning, I would say, your mileage may vary with my kludgy fix, use caution!

Prototype answered 24/7, 2017 at 22:56 Comment(4)
Worked for me ! Same problem your solution fixed itQuadruplex
Thanks, it works! For Mac, the location is ~/Library/Python/2.7/lib/python/site-packagesGuillen
If you're running Homebrew Python on a mac, the paths to remove are /usr/local/lib/python2.7/dist-packages/OpenSSL and /usr/local/lib/python2.7/dist-package/pyOpenSSL-*.Talcahuano
If you're using miniconda/conda env on mac then the following paths. ~/miniconda3_path/lib/python3.6/site-packages/OpenSSL* ~/miniconda3_path/lib/python3.6/site-packages/pyOpen*Hereon
I
0

Below method worked for me, I am using Ubuntu 20.04 and wanted to install Objection for Runtime manipulation and dynamic analysis of iOS apps.

Short Background:

I noticed that when I fired pip3 install objection in terminal it gave me same error as you but the directory path was little bit different. In my case it was related to python3.8, so I did following things

Solution:

rm -rf /home/smshrimant/.local/lib/python3.8/site-packages/OpenSSL/

sudo rm -rf /usr/local/lib/python3.8/dist-packages/OpenSSL/
Imperator answered 4/12, 2020 at 6:7 Comment(0)
A
-2

Upgrading pyOpenSSL to 16.2.0 fixes it.

pip uninstall pyOpenSSL
pip install pyOpenSSL==16.2.0

There is an issue with version compatibility.

Arrivederci answered 11/9, 2017 at 9:33 Comment(1)
As mentioned in comments on other answers, this does not work because any invocation of pip triggers the error, even an uninstall.Talcahuano

© 2022 - 2024 — McMap. All rights reserved.