ImportError: cannot import name 'ChaCha20_Poly1305' from 'Crypto.Cipher'
Explains why `from Crypto.Cipher import ChaCha20_Poly1305` throws ImportError on old pycryptodome installs and how to fix it by upgrading to a version that ships the cipher. Use when other Crypto.Cipher imports work but ChaCha20_Poly1305 does not. Not for `No module named 'Crypto'`.
ImportError: cannot import name 'ChaCha20_Poly1305' from 'Crypto.Cipher'
TL;DR: your pycryptodome is too old to include ChaCha20_Poly1305. Run pip install --upgrade pycryptodome and the import works. If you are stuck on a distro-packaged version, install from pip instead of the system package.
ImportError: cannot import name 'ChaCha20_Poly1305' from 'Crypto.Cipher'The fix
- Check what you have:
python -c "import Crypto; print(Crypto.__version__)"- Upgrade:
pip install --upgrade pycryptodomeOn Debian/Ubuntu with a system package, prefer pip in a virtualenv over apt's python3-crypto, which lags behind.
- Verify:
python -c "from Crypto.Cipher import ChaCha20_Poly1305; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=pycryptodome+ChaCha20_Poly1305'
When this applies
from Crypto.Cipher import AESworks but ChaCha20_Poly1305 fails.- You are on an old distro release or a pinned old pycryptodome.
- The traceback shows a Crypto/Cipher/init.py whose all lacks the cipher.
When it does NOT apply
- Nothing under Crypto imports, which is a broken install, not a version gap.
- The error is
No module named 'Crypto', which means it is not installed.
Why this happens
pycryptodome adds ciphers over time and keeps the public import surface in sync with what the installed version ships. Old environments silently lack newer ciphers, and the ImportError is the only signal. Pinning a minimum version like pycryptodome>=3.19 in requirements prevents regressions.
Compatibility
ChaCha20_Poly1305 needs a modern pycryptodome 3.x. System packages on older Debian/Ubuntu are the usual source of the stale version.