Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correctly installing pyOpenSSL for Python (Windows)

I'm trying to make an application that automatically updates a Google Plus spreadsheet. In order to do this I had to set up gspread, which also requires pyOpenSSL in order to work. Without it, it throws this error:

CryptoUnavailableError: No crypto library available

Using pip, I type the command:

pip install pyopenssl

And import using:

from OpenSSL import SSL

When I try to run the code, I receive the following error:

ImportError: No module named cryptography.hazmat.bindings.openssl.binding

I've tried reinstalling pyOpenSSL multiple times, and also tried reinstalling the cryptography dependency (as well as attempting to install previous versions of pyOpenSSL).

This problem is documented a few times, but the only solution I haven't tried is doing a fresh install of python, or the OS.

Any suggestions? Thanks in advance.

like image 507
Constantly Confused Avatar asked Feb 05 '16 19:02

Constantly Confused


People also ask

How do I install pip tool in Python?

Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process. Voila!

Where is pyOpenSSL installed?

If you are installing in order to develop on pyOpenSSL, move to the root directory of a pyOpenSSL checkout, and run: $ pip install -e . As of 0.14, pyOpenSSL is a pure-Python project.


1 Answers

Good luck with that. Debugging ImportError issues on Windows is not for the faint of the heart.

Even though the ImportError refers to cryptography.hazmat.bindings.openssl.binding this does not need to be the original problem. For whatever reasons I often have ImportError shadowing another problem.

The first thing I would try is to run

python -v -c "from OpenSSL import SSL"

and capture the output. Look for any problems close to the final error.

It could be one of the following:

  • cffi failing to compile the bindings (the precompiled bindings should have been installed by pip install, but sometimes stuff breaks...)
  • the bindings trying to import the SSL DLLs which are not available (but should also be pulled by pip install, but I am not quite sure about that)
  • the DLLs being available but not loadable because some dependent DLL is missing, which could be the visual studio runtime for example.

My bet would be on the last point. The only thing that ever helps me was to open the relevant module.pyd with Dependency Walker. More often than not some weird problem (like another DLL being found with the wrong architecture) would turn out to be the reason.

Good luck!

like image 151
Bluehorn Avatar answered Sep 22 '22 03:09

Bluehorn