ImportError: cannot import name 'PasswordHasher' from 'argon2'
Explains why `from argon2 import PasswordHasher` throws ImportError when the wrong `argon2` distribution is installed, and how to fix it by replacing it with argon2-cffi. Use when argon2 imports but has no PasswordHasher. Not for `No module named 'argon2'`.
ImportError: cannot import name 'PasswordHasher' from 'argon2'
TL;DR: you installed the dead argon2 distribution instead of argon2-cffi. Run pip uninstall -y argon2 then pip install argon2-cffi, and PasswordHasher imports fine.
ImportError: cannot import name 'PasswordHasher' from 'argon2'The fix
- Check which one you have:
pip show argon2If it shows the plain argon2 project, that is the wrong one.
- Swap it:
pip uninstall -y argon2
pip install argon2-cffi- Verify:
python -c "from argon2 import PasswordHasher; print(PasswordHasher().hash('pw')[:10])"Expected output: a hash prefix like $argon2id.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=argon2+PasswordHasher+ImportError'
When this applies
import argon2works but PasswordHasher is missing.pip show argon2reports the squatter distribution.- The error appeared right after
pip install argon2.
When it does NOT apply
No module named 'argon2', which means nothing usable is installed.cannot import name 'hash_secret_raw' from 'argon2', which is the low-level API living one module deeper.
Why this happens
Two distributions, one import name. pip resolves pip install argon2 to the older squatter project, and Python imports whichever argon2 is on the path. The squatter's module exists but has a different API, so you get an ImportError instead of the clearer ModuleNotFoundError. Uninstalling the squatter removes the ambiguity.
Compatibility
argon2-cffi 18+. The squatter argon2 distribution should never be installed.
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.