ModuleNotFoundError: No module named 'cryptography'
Explains why `import cryptography` throws ModuleNotFoundError and how to fix it with `pip install cryptography`. Use when the package is missing from a fresh environment. Not for default_backend or _rust import errors.
ModuleNotFoundError: No module named 'cryptography'
TL;DR: run pip install cryptography. It was probably only a transitive dependency; declare it directly.
ModuleNotFoundError: No module named 'cryptography'The fix
pip install cryptographyVerify:
python -c "from cryptography.fernet import Fernet; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=cryptography+No+module+named+pip+install'
When this applies
- Fresh virtualenvs, containers, or CI runners.
- It worked locally because paramiko or pyOpenSSL pulled it in.
- Minimal Docker images.
When it does NOT apply
cannot import name 'default_backend', which is a version problem with it installed.No module named 'cryptography.hazmat.bindings._rust', which is a broken install.
Why this happens
Nearly everything in Python crypto depends on cryptography, so it feels ubiquitous, but feeling ubiquitous is not being declared. When the package that dragged it in is removed or its extras change, the import breaks. Direct dependencies beat transitive ones.
Compatibility
cryptography 41+ on all supported Pythons. Ships Rust-based wheels; needs no compiler on common platforms.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.