tslearn-team/tslearn

[Error] ModuleNotFoundError: No module named 'tslearn.metrics.cysax'

NimaSarajpoor opened this issue · 1 comments

Describe the bug
I got an error when I was trying to run pytest on one of the unit tests. It cannot find the module tslearn.metrics.cysax

To Reproduce
If it helps, I did the following step:

# in my conda environment
# in tslearn directory

pip install -r requirement.txt
python setup.py install 
pytest tslearn/tests/test_metrics.py

Expected behavior
The file does exists. So, there shouldn't have been a problem! I also checked out the setup.cfg but couldn't figure out the cause.

Environment (please complete the following information):

  • OS: Win10
  • tslearn version: 0.5.2

Additional context
I am providing the error below.

$ pytest tslearn/tests/test_metrics.py
============================= test session starts =============================
platform win32 -- Python 3.8.5, pytest-7.1.2, pluggy-1.0.0
rootdir: E:\+Machine_Learning_Journey\contributions\tslearn, configfile: setup.cfg
plugins: anyio-3.5.0
collected 0 items / 1 error

=================================== ERRORS ====================================
_______________ ERROR collecting tslearn/tests/test_metrics.py ________________
ImportError while importing test module 'E:\+Machine_Learning_Journey\contributions\tslearn\tslearn\tests\test_metrics.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Users\nimas\anaconda3\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tslearn\tests\test_metrics.py:4: in <module>
    import tslearn.metrics
tslearn\metrics\__init__.py:18: in <module>
    from .sax import cdist_sax
tslearn\metrics\sax.py:2: in <module>
    from .cysax import cydist_sax
E   ModuleNotFoundError: No module named 'tslearn.metrics.cysax'
============================== warnings summary ===============================
<frozen importlib._bootstrap>:219
  <frozen importlib._bootstrap>:219: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 80 from C header, got 88 from PyObject

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ===========================
ERROR tslearn/tests/test_metrics.py
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
========================= 1 warning, 1 error in 1.72s =========================

(Already mentioned in #378. I am just providing the same stuff here)


After banging my head several times to a wall, I think the following steps helped me solve the issue!

$pip install pytest-cython
$CC=gcc python setup.py build_ext --inplace

And, then:

$pytest tslearn/tests/test_metrics.py
============================= test session starts =============================
platform win32 -- Python 3.8.5, pytest-7.1.2, pluggy-1.0.0
rootdir: E:\+Machine_Learning_Journey\contributions\tslearn, configfile: setup.cfg
plugins: anyio-3.5.0, cython-0.2.0
collected 16 items

tslearn\tests\test_metrics.py ................                           [100%]

============================== warnings summary ===============================
<frozen importlib._bootstrap>:219
  <frozen importlib._bootstrap>:219: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 80 from C header, got 88 from PyObject

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================== 16 passed, 1 warning in 7.56s ========================


I saw this github issue and tried out the steps above. I was wondering if someone else can try it out and see if it works or not.