ModuleNotFoundError: No module named 'Crypto'
Third-person routing: this skill fixes ModuleNotFoundError: No module named 'Crypto' after installing PyCryptodome or pycrypto. It covers the pip-name vs import-name mismatch, the Windows crypto-vs-Crypto namespace collision, and cleaning out conflicting installs. Use when code does from Crypto.Cipher import AES and the import fails. Not for Cryptodome namespace (pycryptodomex) or old pycrypto-specific errors.
ModuleNotFoundError: No module named 'Crypto'
TL;DR: the import is Crypto but the pip package is pycryptodome. Run pip install pycryptodome. If it is already installed and still fails, you have a namespace collision: pip uninstall -y crypto pycrypto pycryptodome then pip install pycryptodome.
ModuleNotFoundError: No module named 'Crypto'The fix
- Install the right package:
python -m pip install pycryptodome
python -c "from Crypto.Cipher import AES; print('ok')"Success check: prints ok.
- If it is already installed but still fails, check for squatters:
python -m pip list 2>/dev/null | grep -i -E "crypto"If you see crypto or pycrypto alongside pycryptodome, nuke all three and reinstall only pycryptodome:
python -m pip uninstall -y crypto pycrypto pycryptodome
python -m pip install --no-cache-dir pycryptodome- On Windows, check site-packages for a lowercase
cryptofolder and delete it by hand if the uninstall left it behind.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=pycryptodome+No+module+named+Crypto'
When this applies
from Crypto.Cipher import AES(or anyCrypto.*import) fails.- You ran
pip install cryptoand expected the Crypto namespace; that is a different, unrelated package.
When it does NOT apply
- Your code imports
Cryptodome(with an o): that needs thepycryptodomexpackage instead. ImportError: cannot import name 'AES' from 'Crypto.Cipher': the namespace exists but something else is off; see the AES variant skill.
Tool and version compatibility
pycryptodome 3.x, Python 3.6+, Windows/Linux/macOS. pycrypto is dead; do not install it.
Why it happens
PyCryptodome installs under the Crypto namespace but is published as pycryptodome on PyPI. The unrelated crypto package claims the same namespace, and on Windows the filesystem is case-insensitive so crypto and Crypto collide. pip then installs PyCryptodome's files into the squatter's directory.
Edge cases
- Multiple interpreters: always use
python -m pipso pip and python are the same environment. - A file named
Crypto.pyin your project shadows the package; rename it. pycryptodomexis the conflict-free alternative (from Cryptodome.Cipher import AES) if you must coexist with old pycrypto.
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.