Error database

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.

The message you saw
AttributeError: module 'numpy' has no attribute 'float'

By Updated

The error

Output
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:

Output
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.

python
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.NaN

Use np.float64 or np.int64 only when you specifically want that exact width.

2. If the traceback points into a library, upgrade that library.

bash
pip install -U theanolibrary

Most 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.

bash
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.

The lessons behind this error.

  • Python for AI

    NumPy

    NumPy lets you do one operation to millions of numbers at once instead of one at a time. It is the foundation every AI library in Python is built on.

Back to all errors