Skip to content
Latchkey

Python "AttributeError: module has no attribute" from version skew in CI

Your code calls an attribute that does not exist on the installed version of a library. CI resolved a different version than you developed against, and the API differs between them.

What this error means

Tests fail with "AttributeError: module 'X' has no attribute 'Y'" only in CI, while it works locally - a strong sign the resolved versions differ.

python
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. It was
removed in NumPy 1.24.

Common causes

An unpinned dependency drifted in CI

Without a lockfile, CI installed a newer (or older) version than local, and the attribute exists in one but not the other.

A removed or renamed API

A major upgrade deleted a deprecated alias or renamed a symbol your code still references.

How to fix it

Pin the library and align with the API you use

  1. Compare the version in CI logs to your local environment.
  2. Pin to a version that has the attribute, or update the code to the new API.
  3. Re-run to confirm parity.
Python
# numpy>=1.24 removed np.float; use the builtin
value = float(x)   # was np.float(x)

Lock all dependencies for reproducibility

Compile and commit a lockfile so CI installs the exact versions you tested.

Terminal
pip install pip-tools
pip-compile requirements.in
pip-sync requirements.txt

How to prevent it

  • Commit a lockfile so CI and local resolve identical versions.
  • Watch changelogs for removed/renamed APIs when bumping majors.
  • Run the suite against the pinned versions before merging.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →