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
- Compare the version in CI logs to your local environment.
- Pin to a version that has the attribute, or update the code to the new API.
- 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.txtHow 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
Python "AttributeError: module X has no attribute Y" in CIFix "AttributeError: module X has no attribute Y" in CI - the imported module loaded but the name you accesse…
Python "cannot import name 'Mapping' from collections" in CIFix "ImportError: cannot import name 'Mapping' from 'collections'" in CI - the ABCs were removed from the top…
Pydantic v1 vs v2 API skew breaks CIFix pydantic v1-vs-v2 API skew in CI - v2 renamed validators, config, and serialization methods, so v1-style…