ImportError: No module named cryptography.hazmat.b

2019-06-20 17:06发布

问题:

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.

回答1:

I finally got this. It worked for me:

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


回答2:

Installing it via the venv fixed it for me:

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


回答3:

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

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



回答4:

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.



回答5:

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!!



回答6:

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.



回答7:

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

rm -rf site-packages

ln -s dist-packages site-packages



回答8:

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.



回答9:

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.