ImportError: No module named cryptography.hazmat.bindings._openssl
Asked Answered
E

20

34

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.

Eulogistic answered 11/9, 2015 at 7:59 Comment(3)
Have you found a solution to this? I am having the same issues like you have had in this and the previous question.Plaid
i actually reinstalled all the libraries required. This issue is probably caused by some error in the dependencies.Eulogistic
I'm running into this too. Has anybody else found a way? I just reinstalled all the packages.Demonstrate
E
-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.

Eulogistic answered 23/9, 2015 at 7:7 Comment(1)
I don't think "Re-install the OS" can ever be an accepted answer to any question. Ok, Maybe a Windows updates error question.Entero
S
30

I finally got this. It worked for me:

pip uninstall pyopenssl
pip uninstall cryptography
pip install pyopenssl
pip install cryptography
Sewellel answered 27/1, 2019 at 15:49 Comment(2)
Worked for me. Show here is a short version pip install pyopenssl cryptography --upgradeEsteban
Note: The Python Cryptographic Authority strongly suggests the use of pyca/cryptography where possible. If you are using pyOpenSSL for anything other than making a TLS connection you should move to cryptography and drop your pyOpenSSL dependency.Susurrous
R
17

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
Reasonable answered 29/1, 2023 at 17:11 Comment(0)
P
5

Installing it via the venv fixed it for me:

/opt/eff.org/certbot/venv/local/bin/pip install cryptography interface
Papuan answered 5/11, 2018 at 11:38 Comment(2)
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.)Staffan
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 youPantelleria
P
5

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
Papaw answered 25/3, 2021 at 19:12 Comment(1)
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.Dahlgren
F
4

Using @fredmanre's answer https://mcmap.net/q/436328/-importerror-no-module-named-cryptography-hazmat-bindings-_openssl 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
Foetation answered 21/4, 2023 at 8:32 Comment(0)
B
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://mcmap.net/q/436328/-importerror-no-module-named-cryptography-hazmat-bindings-_openssl 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.

Bullen answered 22/4, 2019 at 9:18 Comment(0)
M
2

Just incase you're experiencing this issue when installing odoo17 in window10 Venv on python3.11. This worked for me.

pip install pyopenssl==22.1.0

You will need to uninstall the existing pyopenssl first.

Monocotyledon answered 1/5 at 9:35 Comment(3)
That looks identical to Fred Manre's or Jri's response. Maybe give them an upvote.Sheena
Very true, though tried to spice it up with my specific issue. But definitely it saved me loads minuets. So upvote i did.Monocotyledon
same case. installing odoo17 in python3.12Harmonium
S
1

Another workaround:

apk add --no-cache py-cryptography

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

Selfeffacing answered 6/4, 2020 at 18:28 Comment(0)
V
0

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

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

Vicinage answered 11/9, 2015 at 9:0 Comment(1)
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.Eulogistic
E
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.

Eulogistic answered 22/9, 2015 at 12:21 Comment(0)
B
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!!

Backstop answered 29/12, 2016 at 8:56 Comment(0)
H
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.

Hyphen answered 1/9, 2017 at 2:10 Comment(0)
O
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
Orlop answered 9/1, 2019 at 6:44 Comment(0)
B
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

Burkley answered 22/12, 2020 at 11:40 Comment(0)
L
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
Lubow answered 27/1, 2023 at 16:31 Comment(0)
J
0

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

Jollenta answered 14/2, 2023 at 13:12 Comment(0)
K
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.

Keheley answered 16/2, 2023 at 15:44 Comment(0)
H
0

Try reinstalling the cryptography package which resolved my issue

pip install --force-reinstall cryptography
Habakkuk answered 4/4, 2023 at 7:45 Comment(0)
B
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
Baca answered 11/4, 2023 at 14:35 Comment(0)
E
-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.

Eulogistic answered 23/9, 2015 at 7:7 Comment(1)
I don't think "Re-install the OS" can ever be an accepted answer to any question. Ok, Maybe a Windows updates error question.Entero

© 2022 - 2024 — McMap. All rights reserved.