AttributeError: module 'numpy' has no attribute 'float' (Python) — how to fix
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
Quick fix: Replace np.float with float (or np.float64), np.int with int (or np.int64), np.object with object, np.str with str, np.complex with complex. If the line is inside a library, upgrade that library; as a last resort pip install "numpy<1.24".
What it means
np.float, np.int and friends were never special NumPy types. They were just other names for Python's built-in float, int and so on. NumPy deprecated them in 1.20 and removed them in 1.24, so any code that still uses them fails as soon as it runs on a newer NumPy.
The same error comes in several variants:
| Removed alias | Use instead |
|---|---|
np.float |
float, or np.float64 for a NumPy dtype |
np.int |
int, or np.int64 / np.int_ |
np.object |
object |
np.str |
str |
np.complex |
complex, or np.complex128 |
np.bool |
bool or np.bool_ |
(np.bool was removed in 1.24 and then added back in NumPy 2.0 as the name for np.bool_. Using bool or np.bool_ works on every version.)
Check your version:
python -c "import numpy; print(numpy.__version__)"
Fix 1: update your own code
Replacing the alias with the built-in doesn't change behaviour, because the alias was the built-in:
# before
arr = np.zeros(10, dtype=np.float)
labels = data.astype(np.int)
# after
arr = np.zeros(10, dtype=float) # float64
labels = data.astype(np.int64)
Find every occurrence:
grep -rnE "np\.(float|int|object|str|complex|bool)\b" --include=*.py .
On NumPy 2.0 also replace np.float_ with np.float64 and np.complex_ with np.complex128, because those underscore aliases were removed in 2.0.
Fix 2: the alias is inside a third-party package
If the traceback ends in site-packages/<somelib>/..., the library is older than your NumPy. Upgrade it first:
pip install -U <somelib>
Most maintained libraries fixed this back in 2023. If the library is unmaintained, pin NumPy below the removal:
pip install "numpy<1.24"
Put that pin in requirements.txt so the next install doesn't undo it. Keep in mind that very old NumPy versions don't have wheels for the newest Python releases, so you may also need an older Python (for example in a virtual environment or a Docker image).
Fix 3: quick patch for code you can't edit
Only as a stopgap, for example in a notebook running an old script, you can put the aliases back before importing the library:
import numpy as np
np.float = float
np.int = int
np.object = object
import old_library
This monkey-patches NumPy for the whole process. Drop it once the library is upgraded.
Last updated 2026-12-04.