joshlk / k-means-constrained

K-Means clustering - constrained with minimum and maximum cluster size. Documentation: https://joshlk.github.io/k-means-constrained
https://github.com/joshlk/k-means-constrained
BSD 3-Clause "New" or "Revised" License
192 stars 43 forks source link

[BUG] installation issues with numpy < 1.23 #30

Closed sconstable closed 2 years ago

sconstable commented 2 years ago

Describe the bug Whilek-means-constrained claims to support numpy>=1.22.0 in setup.py, actually attempting to install and use it results in an error related to the numpy API version:

Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import k_means_constrained
Traceback (most recent call last):
  File "__init__.pxd", line 942, in numpy.import_array
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sconstable/local-dev/venv/lib/python3.10/site-packages/k_means_constrained/__init__.py", line 4, in <module>
    from .k_means_constrained_ import KMeansConstrained
  File "/home/sconstable/local-dev/venv/lib/python3.10/site-packages/k_means_constrained/k_means_constrained_.py", line 18, in <module>
    from .sklearn_import.metrics.pairwise import euclidean_distances
  File "/home/sconstable/local-dev/venv/lib/python3.10/site-packages/k_means_constrained/sklearn_import/metrics/pairwise.py", line 10, in <module>
    from k_means_constrained.sklearn_import.metrics.pairwise_fast import _sparse_manhattan
  File "k_means_constrained/sklearn_import/metrics/pairwise_fast.pyx", line 26, in init k_means_constrained.sklearn_import.metrics.pairwise_fast
  File "__init__.pxd", line 944, in numpy.import_array
ImportError: numpy.core.multiarray failed to import

Minimum working example The following Dockerfile is enough to reproduce the issue for me:

from ubuntu:20.04
RUN apt-get update && apt-get install -y python3-pip
RUN pip3 install numpy==1.22.4 k-means-constrained
RUN python3 -c 'import k_means_constrained'

Versions:

lucamagnasco commented 2 years ago

It happened also to me with mac monterrey and Python 3.9.7

joshlk commented 2 years ago

The issue should be resolved with the latest version. Please update the package using pip install 'k-means-constrained>=0.7.2' and report back

sconstable commented 2 years ago

the confusion has been resolved, k-means-constrained officially requires numpy>=1.23.0 now. thanks!