Fix bcrypt Has No Attribute __about__ Error

This error usually means that Passlib, not your password-hashing code, is trying to read bcrypt.__about__.__version__, an internal bcrypt attribute that newer bcrypt releases no longer provide. The durable fix is to remove or replace Passlib where practical and use the maintained bcrypt package directly; pinning bcrypt to an older compatible release is a short-term fallback. First, confirm whether the message is only a trapped warning or whether startup or password verification actually fails.

Use this table to match the traceback to the right fix.

Symptom Likely Cause Best Next Action
Traceback points to passlib/handlers/bcrypt.py and hashing still works Passlib’s version-reporting code expects bcrypt’s removed __about__ metadata Plan a migration away from Passlib; do not edit site-packages just to hide the warning
The app, worker, or pypi-server will not start Passlib initialization continues beyond the version lookup and reaches another incompatibility Read the complete traceback, then replace, update, or temporarily pin the dependency pair
The traceback later says the password is too long Passlib’s internal backend check rejected a value longer than 72 bytes Validate the password as UTF-8 bytes before it reaches bcrypt
import bcrypt resolves to a project file or unexpected location A local file or conflicting package may be shadowing the installed bcrypt package Rename the local module, rebuild the environment, and verify the import path

Why Passlib Raises This bcrypt Error

Passlib 1.7.4 initializes its bcrypt backend by looking up:

_bcrypt.__about__.__version__

In the common traceback, that lookup occurs in passlib/handlers/bcrypt.py, line 620. The __about__ object was packaging metadata, not part of bcrypt password hashing itself. Newer bcrypt releases no longer expose it, so Passlib raises:

AttributeError: module 'bcrypt' has no attribute '__about__'

This is a compatibility problem between an older Passlib code path and newer bcrypt releases. It does not mean bcrypt failed to install, and it does not mean an existing bcrypt password hash is automatically invalid.

The important question is what happens after the message. Some applications catch the version-read failure, print (trapped) error reading bcrypt version, and continue successfully. Other applications initialize more of Passlib’s bcrypt backend during startup and encounter a later fatal exception.

The same missing metadata lookup can be a nonfatal warning in one application path and part of a startup failure in another.

If your traceback does not mention Passlib, search your own code and dependencies for __about__. Application code should not use bcrypt’s private metadata object to determine the installed version.

How to Fix the bcrypt __about__ Error Without Editing Site-Packages

Choose the repair based on how your application uses Passlib.

Your Situation Preferred Repair
Your app only needs bcrypt password hashes Use the bcrypt package directly for new hashes and verification
Your app has legacy hashes from several Passlib schemes Keep the current verification path temporarily, then migrate to a maintained password-hashing solution that supports those schemes
A third-party package pulls in Passlib Update or replace that package if possible; otherwise use a controlled temporary version pin
You need the service restored immediately Pin bcrypt to the compatible version, test the full authentication flow, and schedule a dependency migration

Step 1: Confirm the Installed Packages and Import Location

Check the packages in the same virtual environment, container, or interpreter that runs the failing application.

python -m pip show bcrypt passlib

Then confirm which bcrypt module Python actually imports:

python -c "import bcrypt; print(bcrypt.__file__); print(getattr(bcrypt, '__version__', 'unknown'))"

If the printed path is inside your project, such as a local bcrypt.py file or bcrypt/ directory, rename that local module and restart with a clean environment. A local file can shadow the installed package and produce misleading import behavior.

I reproduce dependency errors in a clean virtual environment because it separates package conflicts from application code.

If you only need the installed distribution version for diagnostics, use standard package metadata instead of private module attributes:

from importlib.metadata import version
print(version("bcrypt"))

Step 2: Replace Simple Passlib bcrypt Calls With Direct bcrypt Calls

For an application that uses only bcrypt hashes, direct use of bcrypt is usually simpler than retaining Passlib solely for CryptContext.

Install bcrypt in the active environment:

python -m pip install bcrypt

Then replace code shaped like this:

from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
hashed = pwd_context.hash(password)
valid = pwd_context.verify(password, hashed)

with direct bcrypt calls:

import bcrypt
MAX_BCRYPT_PASSWORD_BYTES = 72
def _password_bytes(password: str) -> bytes:
    value = password.encode("utf-8")
    if len(value) > MAX_BCRYPT_PASSWORD_BYTES:
        raise ValueError("Password is too long for bcrypt")
    return value
def hash_password(password: str) -> str:
    password_bytes = _password_bytes(password)
    hashed = bcrypt.hashpw(password_bytes, bcrypt.gensalt())
    return hashed.decode("ascii")
def verify_password(password: str, stored_hash: str) -> bool:
    password_bytes = _password_bytes(password)
    return bcrypt.checkpw(password_bytes, stored_hash.encode("ascii"))

Keep existing bcrypt hashes in the database. bcrypt hashes are self-contained: the stored value includes the information bcrypt needs to verify a password. bcrypt.checkpw() can verify an existing valid bcrypt hash without rehashing it first.

Do not silently truncate passwords in application code. If two different long passwords are cut to the same byte sequence, they become equivalent to bcrypt. Reject an over-limit password clearly during registration, password changes, and login rather than changing what the user entered.

Step 3: Test Hashing, Verification, and Existing Accounts

Before removing Passlib, test both a newly created hash and an existing stored bcrypt hash.

password = "correct horse battery staple"
new_hash = hash_password(password)
assert verify_password(password, new_hash)
assert not verify_password("wrong password", new_hash)

Run the application’s actual registration, login, password-reset, and service-startup tests. If your database contains non-bcrypt Passlib schemes, do not remove Passlib until those accounts have a migration path.

After the code no longer imports Passlib, remove it only if no other dependency requires it. Rebuild the deployment environment rather than relying on a developer machine where old packages may remain installed.

When the Error Is a Warning and When It Stops Startup

With bcrypt 4.1.1, Passlib 1.7.4 can emit the trapped __about__ traceback while still producing and verifying bcrypt hashes. In that case, suppressing the log entry may make the output quieter, but it does not repair the stale compatibility code.

A more serious case occurs when the application initializes Passlib’s bcrypt backend during service startup. A documented pypi-server failure used bcrypt 5.0.0 with Passlib 1.7.4: it first printed the missing __about__ traceback, then continued into backend checks and failed before the server could start.

Do not stop reading at the first AttributeError. Inspect the final exception in the log. The later exception is the one that determines whether the process can continue.

This distinction matters for middleware-heavy applications too. A backend initialization exception can be misreported as an unrelated response, authentication, or CORS problem if an outer layer catches the original failure poorly.

Temporary Workaround: Pin bcrypt to a Compatible Release

If you cannot change the application or its dependencies immediately, pin bcrypt to a release that works with the installed Passlib version. A commonly used short-term compatibility pin for Passlib 1.7.4 is bcrypt 4.0.1.

python -m pip install "bcrypt==4.0.1"

Record that pin in your dependency file:

bcrypt==4.0.1

Then verify the environment contains the intended pair:

python -m pip show bcrypt passlib

Finish this workaround by rebuilding the deployment image or virtual environment from the locked dependency file, then test startup and a real password-verification flow. A local downgrade without a lock file can disappear during the next build or deployment.

Treat this as a compatibility bridge, not a permanent repair. bcrypt is security-sensitive software, and holding it back indefinitely makes dependency maintenance harder. Replacing or removing the stale Passlib dependency is more durable than waiting for an old integration path to become compatible again.

Why Editing Passlib Line 620 Is Not a Real Fix

You may see a suggestion to change this line inside the installed Passlib package:

version = _bcrypt.__about__.__version__

to this:

version = _bcrypt.__version__

That can address only the version lookup. It does not update Passlib’s broader bcrypt compatibility behavior, it can be overwritten on the next install, and it does not resolve later initialization failures.

Use an application-level migration, a maintained upstream dependency update, or a reproducible version pin instead of manually modifying files under site-packages.

Handle the Password-Length Error Separately

In the bcrypt 5.0.0 and Passlib 1.7.4 startup failure path, the missing __about__ message was followed by a separate error: bcrypt rejected a password longer than 72 bytes.

bcrypt measures bytes, not visible characters. A password made entirely of basic ASCII characters uses one byte per character, but many Unicode characters use multiple UTF-8 bytes. A password that looks short enough to a user can exceed bcrypt’s input limit after encoding.

Apply the same password policy consistently across these password-bearing flows:

  • account registration
  • password changes
  • password-reset completion
  • login verification
  • service accounts or generated credentials passed into bcrypt

Do not fix this by slicing input with password[:72]. More importantly, automatic truncation changes authentication semantics and can create password collisions.

If existing users may already have long passwords accepted by an older stack, decide on a migration policy deliberately. A password-policy change may require a password reset or a compatibility layer designed for your authentication system; it should not be an accidental side effect of a bcrypt upgrade.

Confirm the Repair and Prevent It Returning

After applying a fix, use this checklist to verify imports, authentication behavior, and the locked environment:

  • Confirm import bcrypt points to the expected virtual environment or container path.
  • Confirm your code no longer accesses bcrypt.__about__.
  • Start the service from a clean environment, not only from an IDE session.
  • Test a correct password and an incorrect password against a newly generated bcrypt hash.
  • Test a known existing account with a stored bcrypt hash.
  • Test password handling with Unicode input if your application accepts it.
  • Lock the working dependency versions in the project’s dependency configuration.
  • Keep the complete traceback in logs until the migration is finished; do not silence an error before confirming it is nonfatal.

For the specific metadata failure, the relevant upstream record is bcrypt issue #684. If your final traceback differs after the initial warning, troubleshoot the final exception rather than assuming every bcrypt error has the same cause.

Frequently Asked Questions

How Do I Install the bcrypt Module in Python?

Install bcrypt into the virtual environment used by your application.

python -m pip install bcrypt

Verify the import location afterward with python -c "import bcrypt; print(bcrypt.__file__)". If your application still imports Passlib, installing bcrypt alone will not remove Passlib’s outdated __about__ lookup.

Is bcrypt Still Safe?

bcrypt is a password-hashing algorithm, and the __about__ error is a dependency compatibility problem rather than evidence that bcrypt hashes are broken. Security still depends on keeping dependencies maintained, validating password inputs, protecting stored hashes, and using bcrypt through a current, tested library path.

Do not downgrade indefinitely just to preserve an old integration. A temporary pin can restore service, but a maintained dependency path is the safer long-term result.

What Should I Use Instead of bcrypt?

Use bcrypt directly when your application already stores bcrypt hashes and only needs password hashing and verification. If you rely on Passlib for multiple legacy hash formats, choose a maintained solution that can verify those formats while you migrate accounts.

Do not replace bcrypt with a plain fast hash function for passwords. Password storage needs a deliberately slow password-hashing function, not a standalone general-purpose digest.

Is bcrypt Better Than SHA-256 for Passwords?

bcrypt is the appropriate choice for password hashing; plain SHA-256 is not. SHA-256 is designed to be fast, which makes it useful for integrity checks but unsuitable as a standalone password-storage method because attackers can test guesses very quickly.

Use a password-hashing function such as bcrypt for passwords, and reserve SHA-256 for non-password integrity or protocol uses where a fast cryptographic hash is appropriate.

Why Does bcrypt Reject a Long Password?

bcrypt accepts at most 72 bytes of password input in the reported failure path. Validate the UTF-8 encoded byte length before hashing or verifying, because Unicode characters can consume more than one byte.

Reject over-limit passwords rather than silently truncating them. Silent truncation can make different user-entered passwords authenticate as the same bcrypt input.