2

I installed python DTW (Dynamic Time Warping) module via

python -m pip install dtw

When I try to import the module using from dtw import dtw (I'm following http://nbviewer.jupyter.org/github/pierre-rouanet/dtw/blob/master/simple%20example.ipynb) I get an ImportError: cannot import name dtw. I checked that dtw.py and dtw.pyc files are present in C:\Python27\Lib\site-packages. Does anyone know the solution to that problem?

linusg
  • 6,289
  • 4
  • 28
  • 78
Biba
  • 631
  • 9
  • 28
  • 1
    Have you several versions of `python` ta your computer? – Dmitry Mar 03 '17 at 15:43
  • 1
    Maybe it's just `import dtw`? – Alfe Mar 03 '17 at 15:46
  • Check my answer from this topic http://stackoverflow.com/questions/42486550/python-package-installed-but-could-not-import/42487646#42487646 You should use virtualenv – Greg Eremeev Mar 03 '17 at 15:46
  • 3
    what's the name of working file that you saved? Hope you did not save as dtw.py. If yes, rename it to something other than dtw and try. I tried the tutorial and its working fine for me. – Anil_M Mar 03 '17 at 15:53
  • Thanks everybody for your answers! @Anil_M, that was it! I named the file dtw.py and that was the breaker for me. After renaming the file the code works as expected. – Biba Mar 06 '17 at 07:31
  • @Biba, If I post my response as an answer would you accept it? That way this question will get closed. Else it will appear on SO threads as unanswered question. – Anil_M Mar 09 '17 at 17:39
  • Maybe try this project: https://github.com/talcs/simpledtw – SomethingSomething Jun 28 '18 at 13:37

2 Answers2

2

In case you are looking for speed

from cdtw import pydtw
from dtaidistance import dtw
from fastdtw import fastdtw
from scipy.spatial.distance import euclidean
s1=np.array([1,2,3,4],dtype=np.double)
s2=np.array([4,3,2,1],dtype=np.double)

%timeit dtw.distance_fast(s1, s2)
4.1 µs ± 28.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit d2 = pydtw.dtw(s1,s2,pydtw.Settings(step = 'p0sym', window = 'palival', param = 2.0, norm = False, compute_path = True)).get_dist()
45.6 µs ± 3.39 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%timeit d3,_=fastdtw(s1, s2, dist=euclidean)
901 µs ± 9.95 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

fastdtw is 219 times slower than dtaidistance lib and 20x slower than cdtw

Consider changing. Here is dtaidistance git:

https://github.com/wannesm/dtaidistance

To install, just:

pip install dtaidistance
Felipe Mello
  • 395
  • 2
  • 8
0

If we read the official docs, we find the following warning.

Warning: The (pip) package name is dtw-python; the import statement is just import dtw.

Thus, please install dtw-python and your problem shall be solved.

https://dynamictimewarping.github.io/python/

Nikolas Rieble
  • 2,416
  • 20
  • 43