raise AttributeError(
AttributeError: np.float_ was removed in the NumPy 2.0 release. Use np.float64 instead.. Did you mean: ‘float16’?
It looks like you’re encountering an error due to the removal of np.float_ in the NumPy 2.0 release. This change requires updating your code to use np.float64 instead. Here’s how you can fix it:
import numpy as np
# Example usage of np.float_
a = np.array([1.0, 2.0, 3.0], dtype=np.float_)
import numpy as np
# Updated usage to np.float64
a = np.array([1.0, 2.0, 3.0], dtype=np.float64)
np.float_ in your codebase.np.float64: Replace them with np.float64.If your code is more complex and involves various uses of np.float_, you can use the following approach:
– Use an editor with find and replace functionality to replace np.float_ with np.float64.
– Ensure that all other parts of your code that depend on np.float_ are compatible with np.float64.
# Before
import numpy as np
def process_data(data):
if isinstance(data, np.float_):
return data * 2
return data
data = np.array([1.0, 2.0, 3.0], dtype=np.float_)
print(process_data(data[0]))
# After
import numpy as np
def process_data(data):
if isinstance(data, np.float64):
return data * 2
return data
data = np.array([1.0, 2.0, 3.0], dtype=np.float64)
print(process_data(data[0]))
By following these steps, you should be able to update your code to be compatible with NumPy 2.0 and resolve the AttributeError related to np.float_.
运行,chroma run –host 0.0.0.0,chroma向量数据库,抛出异常,Traceback (most recent call last):
File “/opt/miniconda3/envs/arg/bin/chroma”, line 5, in
from chromadb.cli.cli import app
File “/opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/init.py”, line 3, in
from chromadb.api.client import Client as ClientCreator
File “/opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/api/init.py”, line 7, in
from chromadb.api.models.Collection import Collection
File “/opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/api/models/Collection.py”, line 7, in
import chromadb.utils.embedding_functions as ef
File “/opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/utils/embedding_functions.py”, line 7, in
from chromadb.api.types import (
File “/opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/api/types.py”, line 102, in
ImageDType = Union[np.uint, np.int_, np.float_]
^^^^^^^^^
File “/opt/miniconda3/envs/arg/lib/python3.11/site-packages/numpy/init.py”, line 397, in getattr
raise AttributeError(
AttributeError: np.float_ was removed in the NumPy 2.0 release. Use np.float64 instead.. Did you mean: ‘float16’?
The error you’re encountering is due to the recent removal of np.float_ in NumPy 2.0. To resolve this issue, you’ll need to update the chromadb package to replace np.float_ with np.float64.
Here are the steps to fix this issue:
– The error message indicates that the problematic code is in chromadb/api/types.py at line 102.
– Open the types.py file in your editor. The path is /opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/api/types.py.
– Replace np.float_ with np.float64.
– Navigate to the directory where types.py is located.
– Use a text editor (e.g., nano, vim, or any GUI-based editor) to open the file:
nano /opt/miniconda3/envs/arg/lib/python3.11/site-packages/chromadb/api/types.py
– Locate the line:
ImageDType = Union[np.uint, np.int_, np.float_]
ImageDType = Union[np.uint, np.int_, np.float64]
– Save the changes and exit the editor. In nano, you can do this by pressing Ctrl+O to write the file and Ctrl+X to exit.
– Once you have made the changes, restart your application to see if the error is resolved.
# Before
ImageDType = Union[np.uint, np.int_, np.float_]
# After
ImageDType = Union[np.uint, np.int_, np.float64]
chromadb package for any other instances of np.float_ and replace them with np.float64.
Consider Updating the Package: If this issue is due to an outdated version of the chromadb package, check if there is an updated version available that is compatible with NumPy 2.0. You can do this by running:
pip install --upgrade chromadb
chromadb package, consider reporting it on their GitHub repository or issue tracker.By following these steps, you should be able to resolve the AttributeError related to np.float_ and get your application running again.
powered by kaifamiao