ImportError: DLL load failed while importing _bcrypt
Explains why `import bcrypt` throws ImportError: DLL load failed while importing _bcrypt on Windows and how to fix it by upgrading Python past 3.9.1, reinstalling bcrypt, or downgrading to a known-good wheel. Use when bcrypt fails to import on Windows only. Not for Linux import errors.
ImportError: DLL load failed while importing _bcrypt
TL;DR: the compiled bcrypt wheel is broken for your Python build on Windows. Upgrade Python to 3.9.2+ (or newer), then pip install --force-reinstall bcrypt. If that fails, pin a known-good wheel like bcrypt==4.1.1.
ImportError: DLL load failed while importing _bcrypt: The specified module could not be found.The fix
- Check your Python version:
python --versionPython 3.9.0 and 3.9.1 have a known incompatibility with some bcrypt wheels.
- Reinstall bcrypt from a fresh wheel:
pip install --force-reinstall bcrypt- If it still fails, pin a version with good wheels for your Python:
pip install bcrypt==4.1.1- Verify:
python -c "import bcrypt; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=bcrypt+DLL+load+failed+_bcrypt'
When this applies
- Windows only; the same environment works on Linux or macOS.
- The traceback ends at
from ._bcrypt import (inside bcrypt/init.py. - Python 3.9.0/3.9.1 or a fresh venv on Windows.
When it does NOT apply
- Linux
ImportErrorfor _bcrypt, which is usually a glibc or compiler mismatch, not this. ValueError: password cannot be longer than 72 bytes, which is the 4.1 behavior change.
Why this happens
bcrypt ships platform wheels with a compiled Rust/C extension. A wheel built against a different C runtime (or a CPython bug like the 3.9.0/3.9.1 one) produces a DLL the loader rejects. Force-reinstalling pulls the correct wheel for your exact interpreter, and upgrading Python dodges the buggy builds entirely.
Compatibility
Windows, CPython 3.8 through 3.12. The 3.9.0/3.9.1 releases are the notorious ones; 3.9.2+ is fine.
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.