Cannot import 'DistanceMetric' from 'sklearn.metrics'

### Discussed in https://github.com/scikit-learn/scikit-learn/discussions/24302

<div type='discussions-op-text'>

<sup>Originally posted by **anubhavde** August 30, 2022</sup>
# **ImportError: cannot import name 'DistanceMetric' from 'sklearn.metrics' (/home/linux/miniconda3/envs/python_ai/lib/python3.8/site-packages/sklearn/metrics/__init__.py)**

I know **DistanceMetric** can be found in ```sklearn.neighbors``` and not ```sklearn.metrics``` but I still recieve an ImportError. How do I solve this issue?

### **How to reproduce the Error:**
I am trying to run the following code 
```python
import gc, itertools
import scipy as sp 
import numpy as np 
from tqdm.auto import tqdm

import warnings
warnings.filterwarnings("ignore")

import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

from sklearn.preprocessing import StandardScaler, OrdinalEncoder, MinMaxScaler
from sklearn.metrics import roc_auc_score, roc_curve
from sklearn.neighbors import DistanceMetric as _DistanceMetric
from imblearn.over_sampling import SMOTE
```

### **Error Message:**
```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/linux/Workspace/tabular-playground-series-aug-2022/submission.ipynb Cell 3 in <cell line: 16>()
     [14](vscode-notebook-cell:/home/linux/Workspace/tabular-playground-series-aug-2022/submission.ipynb#W0sZmlsZQ%3D%3D?line=13) from sklearn.preprocessing import StandardScaler, OrdinalEncoder, MinMaxScaler
     [15](vscode-notebook-cell:/home/linux/Workspace/tabular-playground-series-aug-2022/submission.ipynb#W0sZmlsZQ%3D%3D?line=14) from sklearn.metrics import roc_auc_score, roc_curve
---> [16](vscode-notebook-cell:/home/linux/Workspace/tabular-playground-series-aug-2022/submission.ipynb#W0sZmlsZQ%3D%3D?line=15) from sklearn.neighbors import DistanceMetric as _DistanceMetric
     [17](vscode-notebook-cell:/home/linux/Workspace/tabular-playground-series-aug-2022/submission.ipynb#W0sZmlsZQ%3D%3D?line=16) from imblearn.over_sampling import SMOTE

File ~/miniconda3/envs/python_ai/lib/python3.8/site-packages/sklearn/neighbors/__init__.py:8, in <module>
      6 from ._ball_tree import BallTree
      7 from ._kd_tree import KDTree
----> 8 from ._distance_metric import DistanceMetric
      9 from ._graph import kneighbors_graph, radius_neighbors_graph
     10 from ._graph import KNeighborsTransformer, RadiusNeighborsTransformer

File ~/miniconda3/envs/python_ai/lib/python3.8/site-packages/sklearn/neighbors/_distance_metric.py:4, in <module>
      1 # TODO: Remove this file in 1.3
      2 import warnings
----> 4 from ..metrics import DistanceMetric as _DistanceMetric
      7 class DistanceMetric(_DistanceMetric):
      8     @classmethod
      9     def _warn(cls):

ImportError: cannot import name 'DistanceMetric' from 'sklearn.metrics' (/home/linux/miniconda3/envs/python_ai/lib/python3.8/site-packages/sklearn/metrics/__init__.py)
```

### **System/Environment Details**
OS: Manjaro Linux x86_64 
Kernel: 5.15.60-1-MANJARO 
Scikit-learn: 1.1.2
</div>

COMMENT:
> Can you check if you have the file: /home/linux/miniconda3/envs/python_ai/lib/python3.8/site-packages/sklearn/metrics/_dist_metrics.pxd?

Yes. I do have the file.

>And what is the output of:

Yes, the output shows exactly like what you have shown.

> I would just try to uninstall and reinstall scikit-learn.

I tried this 2 times before also (when I first faced this particular issue) and once again now. It still didn't work. However I seemed to have found a **workaround** for this issue. As I had mentioned that ```DistanceMetric``` was working with  ```sklearn.neighbors``` but not ```sklearn.metrics``` so I copied the ```_distance_metric.py``` file from ```sklearn.neighbors``` into ```sklearn.metrics``` and reran my program. It successfully ran. 

Thanks @glemaitre

Labels: Needs Triage