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] import error with python 3.8 and numpy < 1.20 #12

Closed awaizman1 closed 3 years ago

awaizman1 commented 3 years ago

Describe the bug when installing k-means-constrained in python3.8 environment with numpy < 1.20 (i.e. 1.19.5) on linux, import fails due to numpy binary incompatibility.

Details: I think the root cause is that during package installation (PEP-517) the numpy that is used to compile the package is numpy>1.13 (as described in pyproject.toml). on python 3.8 this will collect 1.20 (in python 3.6 it will collect 1.19.5). so the package is built with numpy1.20 but if my environment has a different numpy (1.19.5) there is some binary incompatibility issue. maybe its better to remove numpy from pyproject.toml and let it use the installed numpy instead?

Minimum working example

Python 3.8.9 (default, Apr  3 2021, 01:00:00) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from k_means_constrained import KMeansConstrained
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/e101364/views/1v_main/Qstreams/provision-algobb/assaf/lib/python3.8/site-packages/k_means_constrained/__init__.py", line 4, in <module>
    from .k_means_constrained_ import KMeansConstrained
  File "/home/e101364/views/1v_main/Qstreams/provision-algobb/assaf/lib/python3.8/site-packages/k_means_constrained/k_means_constrained_.py", line 18, in <module>
    from .sklearn_import.metrics.pairwise import euclidean_distances
  File "/home/e101364/views/1v_main/Qstreams/provision-algobb/assaf/lib/python3.8/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 1, in init k_means_constrained.sklearn_import.metrics.pairwise_fast
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

Versions:

Thanks

bugra-yilmaz commented 3 years ago

I had the same issue on Python 3.8.5, requirements.txt needs to be updated.

joshlk commented 3 years ago

Hi both,

Thanks for the bug report. Sorry it's taken me so long to get to it. I have updated the dependencies and corresponding tests. The latest version v0.6.0 should work: https://pypi.org/project/k-means-constrained/0.6.0/

Please let me know if you have any issues 😃

Josh