Compiling Fails due to sklearn/metrics/pairwise.py

### Describe the bug

_This may be a duplicate of [29754](https://github.com/scikit-learn/scikit-learn/issues/29754)._ 

Having merged from upstream, the imports in `sklearn/metrics/pairwise.py` do not compile. 

I am getting error:
"sklearn/metrics/_dist_metrics.pyx", line 1, in init sklearn.metrics._dist_metrics"

I have tried rebuilding my conda environment and sklearn.


### Steps/Code to Reproduce

$ python -m sklearn.kernel_approximation

### Expected Results

not an error

### Actual Results

```python
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/conradstevens/scikit-learn/sklearn/kernel_approximation.py", line 20, in <module>
    from .metrics.pairwise import KERNEL_PARAMS, PAIRWISE_KERNEL_FUNCTIONS, pairwise_kernels
  File "/Users/conradstevens/scikit-learn/sklearn/metrics/__init__.py", line 6, in <module>
    from . import cluster
  File "/Users/conradstevens/scikit-learn/sklearn/metrics/cluster/__init__.py", line 28, in <module>
    from ._unsupervised import (
  File "/Users/conradstevens/scikit-learn/sklearn/metrics/cluster/_unsupervised.py", line 21, in <module>
    from ..pairwise import _VALID_METRICS, pairwise_distances, pairwise_distances_chunked
  File "/Users/conradstevens/scikit-learn/sklearn/metrics/pairwise.py", line 46, in <module>
    from ._pairwise_distances_reduction import ArgKmin
  File "/Users/conradstevens/scikit-learn/sklearn/metrics/_pairwise_distances_reduction/__init__.py", line 97, in <module>
    from ._dispatcher import (
  File "/Users/conradstevens/scikit-learn/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py", line 11, in <module>
    from .._dist_metrics import (
  File "sklearn/metrics/_dist_metrics.pyx", line 1, in init sklearn.metrics._dist_metrics
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
$ python -c "import sklearn; sklearn.show_versions()"

System:
    python: 3.12.5 | packaged by conda-forge | (main, Aug  8 2024, 18:31:54) [Clang 16.0.6 ]
executable: /opt/homebrew/Caskroom/miniconda/base/envs/sklearn-dev-3/bin/python
   machine: macOS-14.4.1-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.6.dev0
          pip: 24.2
   setuptools: 72.2.0
        numpy: 2.1.0
        scipy: 1.14.1
       Cython: 3.0.11
       pandas: None
   matplotlib: None
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 10
         prefix: libopenblas
       filepath: /opt/homebrew/Caskroom/miniconda/base/envs/sklearn-dev-3/lib/libopenblasp-r0.3.27.dylib
        version: 0.3.27
threading_layer: openmp
   architecture: Nehalem

       user_api: openmp
   internal_api: openmp
    num_threads: 10
         prefix: libomp
       filepath: /opt/homebrew/Caskroom/miniconda/base/envs/sklearn-dev-3/lib/libomp.dylib
        version: None
```

COMMENT:
I am using windows for installing [goldenverba](https://github.com/weaviate/Verba/tree/main), and encountered the following similar error with preparing the meta data:

`Preparing metadata (pyproject.toml) ... error`

**Steps/Code to Reproduce**

`pip install goldenverba`

**Expected**

**No errors**: a successful installation.

Actual Result:

```
error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [124 lines of output]
      + meson setup C:\Users\HaochengLin\AppData\Local\Temp\pip-install-7c4qw_4k\scikit-learn_715436ce7c184007ab495e4d6782f6ba C:\Users\HaochengLin\AppData\Local\Temp\pip-install-7c4qw_4k\scikit-learn_715436ce7c184007ab495e4d6782f6ba\.mesonpy-1x4b5lnb -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\HaochengLin\AppData\Local\Temp\pip-install-7c4qw_4k\scikit-learn_715436ce7c184007ab495e4d6782f6ba\.mesonpy-1x4b5lnb\meson-python-native-file.ini
      The Meson build system
      Version: 1.7.0
      Source dir: C:\Users\HaochengLin\AppData\Local\Temp\pip-install-7c4qw_4k\scikit-learn_715436ce7c184007ab495e4d6782f6ba
      Build dir: C:\Users\HaochengLin\AppData\Local\Temp\pip-install-7c4qw_4k\scikit-learn_715436ce7c184007ab495e4d6782f6ba\.mesonpy-1x4b5lnb
      Build type: native build
      Project name: scikit-learn
      Project version: 1.5.1
      Activating VS 17.12.4
      C compiler for the host machine: cl (msvc 19.42.34436 "Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34436 for x64")
      C linker for the host machine: link link 14.42.34436.0
      C++ compiler for the host machine: cl (msvc 19.42.34436 "Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34436 for x64")
      C++ linker for the host machine: link link 14.42.34436.0
      Cython compiler for the host machine: cython (cython 3.0.12)
      Host machine cpu family: x86_64
      Host machine cpu: x86_64
      Compiler for C supports arguments -Wno-unused-but-set-variable: NO
      Compiler for C supports arguments -Wno-unused-function: NO
      Compiler for C supports arguments -Wno-conversion: NO
      Compiler for C supports arguments -Wno-misleading-indentation: NO
      Library m found: NO
      Program python found: YES (C:\Users\HaochengLin\Desktop\Verba-Model\venv\Scripts\python.exe)
      Run-time dependency OpenMP for c found: YES 2.0
      Run-time dependency python found: YES 3.13
      Build targets in project: 111

      scikit-learn 1.5.1

        User defined options
          Native files: C:\Users\HaochengLin\AppData\Local\Temp\pip-install-7c4qw_4k\scikit-learn_715436ce7c184007ab495e4d6782f6ba\.mesonpy-1x4b5lnb\meson-python-native-file.ini
          b_ndebug    : if-release
          b_vscrt     : md
          buildtype   : release

      Found ninja.EXE-1.11.1.git.kitware.jobserver-1 at C:\Users\HaochengLin\AppData\Local\Programs\Python\Python313\Scripts\ninja.EXE
      + meson compile
      [1/249] Generating sklearn/write_built_with_meson_file with a custom command
      [2/249] Generating sklearn/utils/_seq_dataset_pxd with a custom command
      [3/249] Generating sklearn/utils/_weight_vector_pxd with a custom command
      [4/249] Copying file sklearn/utils/_cython_blas.pxd
      [5/249] Generating sklearn/metrics/_dist_metrics_pxd with a custom command
      [6/249] Copying file sklearn/utils/_random.pxd
      [7/249] Copying file sklearn/__init__.py
      [8/249] Copying file sklearn/utils/__init__.py
      [9/249] Copying file sklearn/utils/_sorting.pxd
      [10/249] Copying file sklearn/_loss/_loss.pxd
      [11/249] Copying file sklearn/utils/_typedefs.pxd
      [12/249] Copying file sklearn/utils/_openmp_helpers.pxd
      [13/249] Copying file sklearn/utils/_heap.pxd
      [14/249] Copying file sklearn/utils/_vector_sentinel.pxd
      [15/249] Generating sklearn/metrics/_pairwise_distances_reduction/_base_pxd with a custom command
      [16/249] Generating sklearn/metrics/_pairwise_distances_reduction/_datasets_pair_pxd with a custom command
      [17/249] Generating sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer_pxd with a custom command
      [18/249] Copying file sklearn/metrics/__init__.py
      [19/249] Generating sklearn/metrics/_pairwise_distances_reduction/_argkmin_pxd with a custom command
      [20/249] Generating sklearn/_loss/_loss_pyx with a custom command
      [21/249] Generating sklearn/metrics/_pairwise_distances_reduction/_radius_neighbors_pxd with a custom command
      [22/249] Compiling C++ object sklearn/utils/murmurhash.cp313-win_amd64.pyd.p/src_MurmurHash3.cpp.obj
      [23/249] Copying file sklearn/metrics/_pairwise_distances_reduction/_classmode.pxd
      [24/249] Copying file sklearn/metrics/_pairwise_distances_reduction/__init__.py
      [25/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/__check_build/_check_build.pyx
      [26/249] Compiling C object sklearn/__check_build/_check_build.cp313-win_amd64.pyd.p/meson-generated_sklearn___check_build__check_build.pyx.c.obj
      [27/249] Linking target sklearn/__check_build/_check_build.cp313-win_amd64.pyd
         Creating library sklearn\__check_build\_check_build.cp313-win_amd64.lib and object sklearn\__check_build\_check_build.cp313-win_amd64.exp

      [28/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/_isotonic.pyx
      [29/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_heap.pyx
      [30/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_openmp_helpers.pyx
      [31/249] Compiling C object sklearn/utils/_heap.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__heap.pyx.c.obj
      [32/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/murmurhash.pyx
      [33/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/metrics/cluster/_expected_mutual_info_fast.pyx
      [34/249] Compiling C object sklearn/utils/_openmp_helpers.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__openmp_helpers.pyx.c.obj
      [35/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_typedefs.pyx
      [36/249] Linking target sklearn/utils/_heap.cp313-win_amd64.pyd
         Creating library sklearn\utils\_heap.cp313-win_amd64.lib and object sklearn\utils\_heap.cp313-win_amd64.exp

      [37/249] Linking target sklearn/utils/_openmp_helpers.cp313-win_amd64.pyd
         Creating library sklearn\utils\_openmp_helpers.cp313-win_amd64.lib and object sklearn\utils\_openmp_helpers.cp313-win_amd64.exp

      [38/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_fast_dict.pyx
      [39/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_random.pyx
      [40/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/cluster/_hdbscan/_reachability.pyx
      [41/249] Generating sklearn/utils/_seq_dataset_pyx with a custom command
      [42/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_sorting.pyx
      [43/249] Compiling C object sklearn/_isotonic.cp313-win_amd64.pyd.p/meson-generated_sklearn__isotonic.pyx.c.obj
      [44/249] Generating sklearn/utils/_weight_vector_pyx with a custom command
      [45/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_cython_blas.pyx
      [46/249] Compiling C object sklearn/utils/murmurhash.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils_murmurhash.pyx.c.obj
      ..\sklearn\utils\src/MurmurHash3.h(16): warning C4142: 'uint32_t': benign redefinition of type
      C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\include\stdint.h(24): note: see declaration of 'uint32_t'
      [47/249] Compiling C object sklearn/utils/_sorting.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__sorting.pyx.c.obj
      [48/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/sparsefuncs_fast.pyx
      [49/249] Compiling C object sklearn/utils/_typedefs.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__typedefs.pyx.c.obj
      [50/249] Compiling C object sklearn/utils/_random.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__random.pyx.c.obj
      [51/249] Compiling C++ object sklearn/utils/_fast_dict.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__fast_dict.pyx.cpp.obj
      sklearn/utils/_fast_dict.cp313-win_amd64.pyd.p/sklearn/utils/_fast_dict.pyx.cpp(26950): warning C4551: function call missing argument list
      sklearn/utils/_fast_dict.cp313-win_amd64.pyd.p/sklearn/utils/_fast_dict.pyx.cpp(30800): warning C4551: function call missing argument list
      sklearn/utils/_fast_dict.cp313-win_amd64.pyd.p/sklearn/utils/_fast_dict.pyx.cpp(30801): warning C4551: function call missing argument list
      sklearn/utils/_fast_dict.cp313-win_amd64.pyd.p/sklearn/utils/_fast_dict.pyx.cpp(30802): warning C4551: function call missing argument list
      [52/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_vector_sentinel.pyx
      [53/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/_isfinite.pyx
      [54/249] Compiling Cython source C:/Users/HaochengLin/AppData/Local/Temp/pip-install-7c4qw_4k/scikit-learn_715436ce7c184007ab495e4d6782f6ba/sklearn/utils/arrayfuncs.pyx
      [55/249] Compiling Cython source sklearn/utils/_weight_vector.pyx
      [56/249] Compiling Cython source sklearn/utils/_seq_dataset.pyx
      [57/249] Compiling C++ object sklearn/utils/_vector_sentinel.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__vector_sentinel.pyx.cpp.obj
      sklearn/utils/_vector_sentinel.cp313-win_amd64.pyd.p/sklearn/utils/_vector_sentinel.pyx.cpp(15416): warning C4551: function call missing argument list
      [58/249] Linking target sklearn/utils/murmurhash.cp313-win_amd64.pyd
         Creating library sklearn\utils\murmurhash.cp313-win_amd64.lib and object sklearn\utils\murmurhash.cp313-win_amd64.exp

      [59/249] Linking target sklearn/_isotonic.cp313-win_amd64.pyd
         Creating library sklearn\_isotonic.cp313-win_amd64.lib and object sklearn\_isotonic.cp313-win_amd64.exp

      [60/249] Linking target sklearn/utils/_typedefs.cp313-win_amd64.pyd
         Creating library sklearn\utils\_typedefs.cp313-win_amd64.lib and object sklearn\utils\_typedefs.cp313-win_amd64.exp

      [61/249] Generating sklearn/metrics/_dist_metrics_pyx with a custom command
      [62/249] Coninja: error: mkdir(sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.cp313-win_amd64.pyd.p/sklearn/metrics/_pairwise_distances_reduction): No such file or directory
      mpiling C object sklearn/utils/_cython_blas.cp313-win_amd64.pyd.p/meson-generated_sklearn_utils__cython_blas.pyx.c.obj
      [63/249] Generating sklearn/metrics/_pairwise_distances_reduction/_datasets_pair_pyx with a custom command
      ninja: build stopped: .
      Activating VS 17.12.4
      INFO: automatically activated MSVC compiler environment
      INFO: autodetecting backend as ninja
      INFO: calculating backend command to run: C:\Users\HaochengLin\AppData\Local\Programs\Python\Python313\Scripts\ninja.EXE
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
```

Would you like to check to see if this issue could be resolved or reproduced?

Labels: Question