A Python script of mine is failing with:
Traceback (most recent call last):
File \"./inspect_sheet.py\", line 21, in
main()
File \"./i
I had a similar error:
from OpenSSL import rand, crypto, SSL
File "/usr/local/lib/python3.5/dist-packages/OpenSSL/SSL.py", line 112, in <module>
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: module 'lib' has no attribute 'SSL_ST_INIT'
and none of the other answers could fix it, because pip could not install anything. Instead, what I did was this from the terminal first:
sudo rm -r /usr/local/lib/python3.5/dist-packages/OpenSSL
Then reinstalled pyopenssl with pip:
sudo pip install pyopenssl
and everything was gravy.
This worked for me:
sudo apt remove python-openssl
This is an older post, so I'm answering to hopefully help someone in late 2019... my problem had to do with Python 2 vs 3. I'm using Python 3 exclusively; no more legacy Python. But my OS (eg, Ubuntu 16.04) still has Python 2.7 installed. Thus when running global pip
by default (eg, not in a virtualenv), I was calling the Python 2 version of pip
.
For me, I used the following to fix this issue.
Uninstall docker-compose
:
sudo pip3 uninstall docker-compose
sudo pip uninstall docker-compose
Reinstall docker-compose
for my version of Python:
sudo pip3 install docker-compose
I had this problem on MacOS with python 2 and 3 installed via brew. It turns out that brew uninstall
ing python and python@2 does not remove any libraries which were installed for those versions of python; i.e. in:
/usr/local/lib/python3.7/site-packages/
and
/usr/local/lib/python2.7/site-packages/
Something in there was not right, so what worked for me was to delete/move all the installed libraries for brew's python 2 and 3 and start again (and make sure only to use virtualenvs from here on):
brew uninstall --ignore-dependencies python@2
brew uninstall --ignore-dependencies python
sudo mv /usr/local/lib/python3.7 ~/python3.7libs-backup
sudo mv /usr/local/lib/python2.7 ~/python2.7libs-backup
brew install python
brew install python@2
I had the same problem on Ubuntu 16.04, but with the following twist: when virtualenv was activated (. venv/bin/activate
before running celery workers with pysolr, requests, etc in my case) - everything worked perfectly, but when I ran celery from command line using full paths, and python paths - there was a problem (and same problem running from supervisord ). Also, if important, virtualenv has been bundled elsewhere on the machine with same Ubuntu version.
Solution was simple: adding /full/path/to/venv/bin
to PATH ( as advised here https://serverfault.com/questions/331027/supervisord-how-to-append-to-path ) solved this.
Unfortunately, I have not yet pin-pointed what kind of update caused this, but hopefully this may help someone.
I experienced the same issue recently and after few hours investigation, I found out that it was caused by New cryptography 2.0 upgrade. This upgrade will break many packages using pyopenssl (like Sentry, Google Analytics and etc). Just downgrade it to 1.9 will solve the problem.
Be cautious if you are using "pip install -U", it will automatically upgrade packages that are not listed in requirements.txt.