I am using NumPy 1.24.0.
On running this sample code line,
import numpy as np
num = np.float(3)
I am getting this error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ubuntu/.local/lib/python3.8/site-packages/numpy/__init__.py", line 284, in __getattr__
raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'float'
How can I fix it?
6
Answers
I removed numpy.py and then updated my NumPy installation. It worked!
Note: NumPy version 1.23.3
The answer is already provided in the comments by @mattdmo and @tdelaney:
NumPy 1.20 (release notes) deprecated
numpy.float
,numpy.int
, and similar aliases, causing them to issue a deprecation warningNumPy 1.24 (release notes) removed these aliases altogether, causing an error when they are used
In many cases you can simply replace the deprecated NumPy types by the equivalent Python built-in type, e.g.,
numpy.float
becomes a "plain" Pythonfloat
.For detailed guidelines on how to deal with various deprecated types, have a closer look at the table and guideline in the release notes for 1.20:
If you have dependencies that use the deprecated types, a quick workaround would be to roll back your NumPy version to 1.24 or less (as suggested in some of the other answers), while waiting for the dependency to catch up. Alternatively, you could create a patch yourself and open a pull request, or monkey patch the dependency in your own code.
In the 1.24 version:
pip install "numpy<1.24"
to work around it.I solved by updating my "openpyxl" using
The error came up while trying to read an excel file
I faced the same issue when I was reading a .xlsx file. You can convert it to csv and this will resolve the issue. However for updating numpy some times you need to get the directory of numpy package:
For updating it you can use the code below:
You can also check this page:
How can I upgrade NumPy?
Try to use simple "monkey path". Add line like
or
in case module ‘numpy’ has no attribute ‘int’
module ‘numpy’ has no attribute ‘object’
and so on… (if problem with last Numpy versions)