ImportError: No module named cryptography.hazmat.bindings._openssl

35,172

Solution 1

This answer may look lame, but this is what worked out for me. I actually reinstalled the os. That way it removed all the other libraries which i earlier installed. One of those libraries might be the culprit, that interferes with the cryptography files and openssl. I was unable to trace back which module/library is causing the mentioned errors. Once OS was reinstalled, i went on to install cyptography, openssl using the links you probably would have done before coming into this error.

Before you go through my way, make sure the six.py has the version 1.9.0 in both /Library/Python/2.7/site-packages and /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

Even if you go through my way, do the above also.

I was so desperate that i reinstalled the os. I came to this decision because the same code that is in production works while it doesnt work on dev. I understood its some dependency error.

Solution 2

I finally got this. It worked for me:

pip uninstall pyopenssl
pip uninstall cryptography
pip install pyopenssl
pip install cryptography

Solution 3

Installing it via the venv fixed it for me:

/opt/eff.org/certbot/venv/local/bin/pip install cryptography interface

Solution 4

I had a similar problem in a virtualenv on a Mac. I followed the advice of the answer from zhangzhy2000, but also I needed to uninstall and reinstall pyasn1.

This left me with these steps

cd ~/.virtualenvs/my-virtual-env/bin
source activate
pip uninstall pyopenssl
pip uninstall cryptography
pip uninstall pyasn1
pip install pyopenssl
pip install cryptography
pip install pyasn1

Solution 5

I've encountered the same issue when I've wanted to install Scrapy for Anaconda3.

I think that actually installing Twisted broke this. Any attempt to use pip/conda failed because this message.

I saw the proposition https://stackoverflow.com/a/54389947/1137529 of zhangzhy2000 above, a but I failed to install anything.

What actually happen, that once there was Python module to handle SSL, but it was droped. Now (after upgrading some dependency of Scrapy / Twisted) Anaconda relies on OS to handle SSL.

For Windows 10 64 bit that was I did:

  1. I installed sasl-0.2.1-cp37-cp37m-win_amd64.whl (from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame). This actually didn't help me.

  2. I installed Win64OpenSSL-1_1_1b.exe - Open SSL (from https://slproweb.com/products/Win32OpenSSL.html)

  3. I run pip3 install pyopenssl==19.0.0 that install pyopenssl and cryptography for me.

(And then I install twisted and scrapy that are irrelevant here).

I want to re-iterate, support of SSL was dropped from Python, now it relies on OS, so OS-specific packages for SSL should be installed.

Share:
35,172
Prajapathy3165
Author by

Prajapathy3165

Updated on March 26, 2021

Comments

  • Prajapathy3165
    Prajapathy3165 about 3 years

    CryptoUnavailableError: No crypto library available and from oauth2client import crypt failure.

    I had the above error mentioned in the link. I was able to fix that by reinstalling pyOpenSSL and cryptography. But now the following error is being raised.

    ImportError: No module named cryptography.hazmat.bindings._openssl
    

    Here _openssl is a unix executable file(_openssl.so). The following is the import statement

    from cryptography.hazmat.bindings._openssl import ffi, lib
    

    The above code is in bindings.py in cryptography module. These are all linked to gspread authentication using oauth2client. Please help me out. Im struggling with this.

    Update: The issue was caused by some dependency failure. I was unable to find where the dependency was failing though.. Reinstalled all the libraries from top. That kind of fixed the issue.

  • Prajapathy3165
    Prajapathy3165 over 8 years
    There is already a cryptography source in the root of my project. I tried the link you provided but that source did not have _openssl.so or any such files which raised error.
  • Andrew
    Andrew about 6 years
    I don't think "Re-install the OS" can ever be an accepted answer to any question. Ok, Maybe a Windows updates error question.
  • abhikarma1493
    abhikarma1493 over 4 years
    This finally worked for me. Just had to use the virtualenv pip to install all the missing dependencies. (My Amazon Linux certbot-auto had updated to 0.37.1 and could not find all these modules.)
  • Joe
    Joe almost 2 years
    Thanks, this was the fix. I use pip-tools to handle installing deps in my venv and for some reason these same requirements installed via pip-tools don't install these three packages properly, but doing as @kirby suggests here does work. I suspect that pip-tools is not handling the underlying binaries (in rust) installation correctly, but just an educated guess.