Python "AttributeError: module X has no attribute Y" in CI
The module imported successfully, but the attribute you referenced does not exist on it. The usual cause is a different package version than the code expects, or a local file shadowing the real module.
What this error means
Code fails with "AttributeError: module 'X' has no attribute 'Y'". It often appears after a dependency upgrade or when a local file shares a third-party module name.
AttributeError: module 'numpy' has no attribute 'int'Common causes
A version removed or renamed the attribute
CI resolved a newer release in which the function or alias was deprecated and deleted, so the name is gone.
A local file shadows the real module
A file named like the library (e.g. email.py, random.py) is imported instead of the package, so the expected attribute is absent.
How to fix it
Pin a version that still defines the name
- Check which version installed in CI and read its changelog for the removed name.
- Either migrate to the replacement API or pin a version that still exports it.
- Recompile the lockfile so the pin holds.
# numpy removed the np.int alias; use the builtin
pip install "numpy<1.24"Rename a shadowing local module
If a project file has the same name as the import, rename it so Python loads the real package.
git mv email.py mailer.pyHow to prevent it
- Lock dependency versions so the attribute surface is stable in CI.
- Avoid naming local files after standard library or popular packages.
- Migrate off deprecated aliases before they are removed upstream.