module 'numpy' has no attribute 'int' / 'float' / 'bool8' / 'float_'
AttributeError: module 'numpy' has no attribute 'int' (or 'float', 'bool8', 'float_', 'NaN') means your code or a library uses an alias NumPy removed: the builtin aliases in 1.24, the rest in 2.0. Use int/float or np.int64/np.float64, np.nan, np.prod. Tested on NumPy 1.26.4 and 2.3.4.
1. Which np.* names exist on NumPy 1.26 vs 2.x
import numpy as np
print(np.__version__)
for name in ["int", "float", "bool", "object", "str", "long", "bool8", "float_", "trapz", "product", "NaN", "Inf"]:
try:
getattr(np, name)
print(f"np.{name}: ok")
except AttributeError as e:
print(f"np.{name}: AttributeError: {str(e)[:110]}")
NumPy 1.26.4 (Python 3.11):
/w/b1.py:5: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.
getattr(np, name)
/w/b1.py:5: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
getattr(np, name)
/w/b1.py:5: FutureWarning: In the future `np.str` will be defined as the corresponding NumPy scalar.
getattr(np, name)
/w/b1.py:5: FutureWarning: In the future `np.long` will be defined as the corresponding NumPy scalar.
getattr(np, name)
/w/b1.py:5: DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`. (Deprecated NumPy 1.24)
getattr(np, name)
1.26.4
np.int: AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this er
np.float: AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid t
np.bool: AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this
np.object: AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoi
np.str: AttributeError: module 'numpy' has no attribute 'str'.
`np.str` was a deprecated alias for the builtin `str`. To avoid this er
np.long: AttributeError: module 'numpy' has no attribute 'long'
np.bool8: ok
np.float_: ok
np.trapz: ok
np.product: ok
np.NaN: ok
np.Inf: ok
NumPy 2.3.4 (Python 3.14.7):
/w/b1.py:5: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
getattr(np, name)
/w/b1.py:5: FutureWarning: In the future `np.str` will be defined as the corresponding NumPy scalar.
getattr(np, name)
2.3.4
np.int: AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this er
np.float: AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid t
np.bool: ok
np.object: AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoi
np.str: AttributeError: module 'numpy' has no attribute 'str'.
`np.str` was a deprecated alias for the builtin `str`. To avoid this er
np.long: ok
np.bool8: AttributeError: module 'numpy' has no attribute 'bool8'
np.float_: AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.
np.trapz: ok
np.product: AttributeError: module 'numpy' has no attribute 'product'
np.NaN: AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.
np.Inf: AttributeError: `np.Inf` was removed in the NumPy 2.0 release. Use `np.inf` instead.
Three different stories hide behind the same AttributeError. np.int, np.float, np.object and np.str were aliases for the Python builtins, removed in NumPy 1.24, and fail on both versions. np.float_, np.NaN, np.Inf, np.bool8 and np.product still worked on 1.26.4 and were removed in 2.0. And np.bool and np.long went the other way: missing on 1.26.4, back on 2.3.4 as NumPy scalar types (the FutureWarnings above). So the same script can fail on old NumPy and work on new, or the reverse. np.trapz still worked on 2.3.4 here; its new name is np.trapezoid (2.0+).
2. Replacements that work on both
import numpy as np
a = np.array([1.5, 2.5])
print(a.astype(int).dtype, a.astype(float).dtype, np.array([1, 0]).astype(bool).dtype)
print(np.int64, np.float64, np.bool_, np.nan, np.inf)
print(np.trapezoid([1, 2, 3]) if hasattr(np, "trapezoid") else "no trapezoid", np.prod([2, 3]))
NumPy 1.26.4 (Python 3.11):
int64 float64 bool
<class 'numpy.int64'> <class 'numpy.float64'> <class 'numpy.bool_'> nan inf
no trapezoid 6
NumPy 2.3.4 (Python 3.14.7):
int64 float64 bool
<class 'numpy.int64'> <class 'numpy.float64'> <class 'numpy.bool'> nan inf
4.0 6
Use the builtin (int, float, bool, object, str) or an explicit NumPy type (np.int64, np.float64, np.bool_); np.nan and np.inf in lower case; np.prod for np.product. np.trapezoid only exists from NumPy 2.0, so if you must support 1.x, use getattr(np, "trapezoid", None) or np.trapz. If the error comes from a library rather than your code (an old scikit-learn, bottleneck or numba calling np.float), upgrade that library or pin numpy<1.24; mismatched compiled extensions give a different error, covered in _ARRAY_API not found / dtype size changed.
Related: NumPy 2 breaking changes, AttributeError: module has no attribute · int64 is not JSON serializable · pandas 3 breaking changes.
Frequently asked questions
What do I replace np.int and np.float with?
The Python builtins int and float, or explicit sized types np.int64 and np.float64. Both work on NumPy 1.x and 2.x.
Why does np.bool work on NumPy 2 but not 1.26?
np.bool was a builtin alias removed in 1.24; NumPy 2 re-added np.bool as the NumPy boolean scalar type. In our test 1.26.4 raised and 2.3.4 worked (with a FutureWarning on access). np.long behaved the same.
The error comes from a library, not my code. What do I do?
Upgrade the library to a release that supports your NumPy version, or pin numpy<1.24 (for np.int/np.float) or numpy<2 (for np.float_, np.NaN) until it does.
Written with AI assistance. Measured on 2026-10-23 in Docker: NumPy 1.26.4 on python:3.11-alpine and NumPy 2.3.4 on python:3-alpine (Python 3.14.7). Outputs pasted unedited (the script truncates long messages). PlainTables is our extension; Python and NumPy are free.