31

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.

Community
  • 1
  • 1
Prajapathy3165
  • 518
  • 1
  • 6
  • 13

19 Answers19

29

I finally got this. It worked for me:

pip uninstall pyopenssl
pip uninstall cryptography
pip install pyopenssl
pip install cryptography
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
zhangzhy2000
  • 291
  • 3
  • 3
  • 2
    Worked for me. Show here is a short version `pip install pyopenssl cryptography --upgrade` – Nitish Nov 04 '22 at 08:14
8

There is an error on by OpenSSL in the new version (23.0.0), so do the following:

pip uninstall pyopenssl
pip install pyopenssl==22.1.0
fredmanre
  • 111
  • 1
  • 5
4

Installing it via the venv fixed it for me:

/opt/eff.org/certbot/venv/local/bin/pip install cryptography interface
rix
  • 10,104
  • 14
  • 65
  • 92
  • 1
    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.) – abhikarma1493 Aug 16 '19 at 18:51
  • This was the issue for me, I replaced with my venv path and indeed, the library was not installed in the venv. Somehow the venv was activated but pip was not installing in there. Thank you – Richard Fogaca Nienkotter Jul 25 '23 at 10:48
4

Using @fredmanre's answer https://stackoverflow.com/a/75276800/20151439 showed an error in my environment. I had to run pip install pyopenssl==22.1.0 with the --user flag:

pip uninstall pyopenssl
pip install --user pyopenssl==22.1.0
iri
  • 41
  • 2
3

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
Kirby
  • 15,127
  • 10
  • 89
  • 104
  • 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. – Joe May 12 '22 at 20:43
2

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.

alexsmail
  • 5,661
  • 7
  • 37
  • 57
1

Another workaround:

apk add --no-cache py-cryptography

Thanks to https://github.com/pyca/cryptography/issues/4264#issuecomment-392849235

trinchet
  • 6,753
  • 4
  • 37
  • 60
0

You should add manually cryptography source in your root path of your project.

https://github.com/pyca/cryptography/tree/master/src

Davy
  • 75
  • 7
  • 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. – Prajapathy3165 Sep 11 '15 at 12:29
0

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
  • 518
  • 1
  • 6
  • 13
0

I have encountered this problem.First, I installed the OpenSSL,And then put the include's OpenSSL The contents of the folder copied to the compiler inside the Microsoft Visual C++ Compiler for Python 2.7\vc\include, the contents of the Lib copy to the Python installation directory inside libs,Adjust the opensll environment variable to git,When you perform where cmd in openssl should be positioned to the OpenSSL installation directory.Uninstall cryptography again,then install again ,My problem is solved!!

任红森
  • 1
  • 1
0

I download the file cryptography-2.0.3-cp36-cp36m-win_amd64.whl

and run :

pip install C:/User/Download/cryptography-2.0.3-cp36-cp36m-win_amd64.whl

then it solved.

Creatint
  • 233
  • 1
  • 2
  • 8
0

Just go to /opt/eff.org/certbot/venv/local/lib64/python2.7 and create a link of dist-packages to site-packages in the same folder. If site-packages is already here, you need to rename it. like

  1. rm -rf site-packages
  2. ln -s dist-packages site-packages
Kirby
  • 15,127
  • 10
  • 89
  • 104
0

This worked for me, else zope and cryptography kept showing dependency of install into each other leading to a deadlock

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

via https://github.com/certbot/certbot/issues/2544#issuecomment-505196160

Ravi Sethia
  • 85
  • 2
  • 9
0

I faced this issue on Windows 10 ,I tried many solutions what worked is the following

pip install pyopenssl --upgrade
pip install urllib3  --upgrade
0

urllib3>=1.26.13 this needs to be added to the requirements

0

It seems to be a dependency problem. For me, installing a specific version of the cryptography package fixed the issue. In most of the cases, using a specific version is the solution.

Ex:

RUN pip install cryptography==38.0.2

PS: I added the above line in the .docker file of my project. If you are not using docker, just install the specific version.

0

Try reinstalling the cryptography package which resolved my issue

pip install --force-reinstall cryptography
S.B
  • 13,077
  • 10
  • 22
  • 49
0

I just figure out use the command to specify the installation worked for me. Check the below command

pip -vvv install --upgrade --force-reinstall cffi
Kotana Sai
  • 1,207
  • 3
  • 9
  • 20
-4

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.

Prajapathy3165
  • 518
  • 1
  • 6
  • 13
  • 13
    I don't think "Re-install the OS" can ever be an accepted answer to any question. Ok, Maybe a Windows updates error question. – Andrew Mar 01 '18 at 15:11