AttributeError: module 'numpy' has no attribute 'float'
NumPy 1.24 removed the np.float, np.int and np.bool aliases. Use the plain Python names, or upgrade the old library that still uses them.
Updated
The error
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 same applies to np.int, np.bool, np.object and np.str. NumPy 2.0 added one more removal:
AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.
What it means
np.float was never a special NumPy type. It was an alias for Python's own float, kept around for historical reasons. The aliases were deprecated in NumPy 1.20 and removed in 1.24 (December 2022). Code that still uses them breaks on any modern NumPy.
Why it happens
Either your own code uses the old names — usually copied from an older tutorial — or a library you depend on does. The traceback tells you which: look at the file path in the last frame. A path inside site-packages means the problem is in a dependency, not in your code.
How to fix it
1. In your own code, substitute directly. The message tells you the safe replacement.
x = np.array(values, dtype=float) # was: dtype=np.float
n = int(count) # was: np.int(count)
mask = arr.astype(bool) # was: np.bool
x = np.nan # was: np.NaNUse np.float64 or np.int64 only when you specifically want that exact width.
2. If the traceback points into a library, upgrade that library.
pip install -U theanolibraryMost maintained packages fixed this years ago. An error today usually means a very old pinned version is installed.
3. If the library is abandoned, pin NumPy below 1.24 as a last resort.
pip install "numpy<1.24"This is a debt, not a fix. Old NumPy conflicts with modern pandas, scikit-learn and PyTorch, so isolate it in its own virtual environment.
4. Never monkey-patch np.float = float in production code. It hides the problem, breaks on NumPy 2 in new ways, and confuses everyone who reads the code later.
How to prevent it
Keep dependencies reasonably current instead of upgrading once every three years — small upgrades hurt less than giant ones. When you see a DeprecationWarning in test output, fix it then, while the old and new behaviour both still work.
Related errors
- A module compiled using NumPy 1.x cannot be run in NumPy 2 — the binary-level version of a NumPy break
- 'DataFrame' object has no attribute 'append'
- ResolutionImpossible: conflicting dependencies