question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

missing module with cryptography.hazmat

See original GitHub issue

Nuitka seems to compile my project fine, but it fails at runtime with this error:

Traceback (most recent call last):
  File "/.../demo_crypt/main.py", line 1, in <module>
    from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
  File "/.../demo_crypt/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py", line 14, in <module cryptography.hazmat.primitives.kdf.scrypt>
    from cryptography.hazmat.primitives import constant_time
  File "/.../demo_crypt/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/constant_time.py", line 11, in <module cryptography.hazmat.primitives.constant_time>
    from cryptography.hazmat.bindings._constant_time import lib
ModuleNotFoundError: No module named 'cryptography.hazmat.bindings._constant_time'

Here are the commands to reproduce it:

  1. Make a virtualenv: python3.7 -m venv demo_crypt/venv
  2. cd demo_crypt
  3. pip install wheel cryptography
  4. pip install -U "https://github.com/Nuitka/Nuitka/archive/develop.zip"
  5. Create a main.py that contains:
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
from cryptography.hazmat.backends import default_backend

def scrypt(passphrase, salt, scrypt_n=1<<12, scrypt_r=12, scrypt_p=1):
    kdf = Scrypt(salt, length=32, n=scrypt_n, r=scrypt_r, p=scrypt_p, backend=default_backend())
    return kdf.derive(passphrase)

print(scrypt(b"junk", b"sea"))
  1. Run python main.py to ensure that there are no errors.
  2. python -m nuitka --follow-imports -j 10 --plugin-enable=pylint-warnings main.py
  3. ./main.bin

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nixarghcommented, Jul 14, 2020

Looks like I’m having some similar issue:

    from cryptography.fernet import Fernet, InvalidToken
  File "/usr/lib/python3/dist-packages/cryptography/fernet.py", line 17, in <module cryptography.fernet>
    from cryptography.hazmat.primitives import hashes, padding
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/padding.py", line 13, in <module cryptography.hazmat.primitives.padding>
    from cryptography.hazmat.bindings._padding import lib
ModuleNotFoundError: No module named 'cryptography.hazmat.bindings._padding'

I’ve got this trying to run my app after compilation.

I’ve checked nuitka/plugins/standard/ImplicitImports.py and it includes:

          elif full_name in (
              "cryptography.hazmat.bindings._openssl",
              "cryptography.hazmat.bindings._constant_time",
              "cryptography.hazmat.bindings._padding",
          ):
              yield "_cffi_backend", True

Any thoughts?

0reactions
kayhayencommented, Jul 16, 2021

Closing this, to me the issue is failed, because I don’t have a reproducer, I don’t know what parts are fixed, please open new issues with full description. The things posted here are probably all different ones, but it’s unclear how relevant they are now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: No module named cryptography.hazmat.bindings ...
I was able to fix that by reinstalling pyOpenSSL and cryptography. But now the following error is being raised. ImportError: No module named ......
Read more >
tfm_ipc: No module named 'cryptography.hazmat.primitives ...
In my case, the cryptography Python module is installed in the virtual environment I am using for Zephyr, and not in the "global"...
Read more >
[Fixed] ModuleNotFoundError: No module named 'cryptography'
How to Fix “ModuleNotFoundError: No module named 'cryptography'” in PyCharm · Open File > Settings > Project from the PyCharm menu. · Select...
Read more >
No module named 'cryptography.hazmat.bindings._openssl'
Summary: net-p2p/deluge-2.0. 3-r8: Python 3.9 error: No module named 'cryptography. hazm... Add an attachment (proposed patch, testcase, etc.)
Read more >
Symmetric encryption — Cryptography 39.0.0.dev1 ...
This is a “Hazardous Materials” module. ... GCM provides no guarantees of ciphertext integrity until decryption is complete. GCM (Galois Counter Mode) is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found