python – Issue with cryptography and paramiko when building .exe via PyInstaller


There is Python 3.5.1 x64, Win 7 x64/. When I tried to run the .exe, I got an error, what can I do about it?

Traceback (most recent call last):
  File "", line 83, in <module>
  File "site-packages\paramiko\", line 1073, in connect
  File "site-packages\paramiko\", line 493, in start_client
  File "site-packages\paramiko\", line 1757, in run
  File "site-packages\paramiko\", line 75, in parse_next
  File "site-packages\paramiko\", line 111, in _parse_kexdh_reply
  File "site-packages\paramiko\", line 1602, in _verify_key
  File "site-packages\paramiko\", line 58, in __init__
  File "site-packages\cryptography\hazmat\backends\", line 35, in def
  File "site-packages\cryptography\hazmat\backends\", line 33, in
ValueError: Multibackend cannot be initialized with no backends. If you are seei
ng this error when trying to use default_backend() please try uninstalling and r
einstalling cryptography.
Failed to execute script test


The solution is described here Creating a method

def patch_crypto_be_discovery():

    Monkey patches cryptography's backend detection.
    Objective: support pyinstaller freezing.

    from cryptography.hazmat import backends

        from cryptography.hazmat.backends.commoncrypto.backend import backend as be_cc
    except ImportError:
        be_cc = None

        from cryptography.hazmat.backends.openssl.backend import backend as be_ossl
    except ImportError:
        be_ossl = None

    backends._available_backends_list = [
        be for be in (be_cc, be_ossl) if be is not None

and call patch_crypto_be_discovery() before working with paramiko

Scroll to Top