-1

I am trying to run the basic feature extraction code from the following site:
musicinformationretrieval.
When I try to run the following code line:

kick_filepaths, snare_filepaths = stanford_mir.download_samples(collection="drum_samples_train")

it shows the following error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-7c764e7836ee> in <module>()
----> 1 kick_filepaths, snare_filepaths = stanford_mir.download_samples(collection="drum_samples_train")

C:\Users\dell\Desktop\stanford-mir-gh-pages\stanford_mir.py in download_samples(collection, download)
     89                 for i in range(1, 11):
     90                     filename = '%s_%02d.wav' % (drum_type, i)
---> 91                     urllib.urlretrieve('http://audio.musicinformationretrieval.com/drum_samples/%s' % filename,
     92                                        filename=os.path.join(collection, filename))
     93         kick_filepaths = [os.path.join(collection, 'kick_%02d.wav' % i) for i in range(1, 11)]

AttributeError: module 'urllib' has no attribute 'urlretrieve'

Please help me to solve this issue.

Jithin Pavithran
  • 1,250
  • 2
  • 16
  • 41
SubodhD
  • 306
  • 5
  • 16

1 Answers1

2

It seems you should use Python 2 insteed of 3. In instruction to stanford_mir there is line:

  1. If you’re totally new, the simplest solution is to download and install Anaconda for Python 2 (2.7), not Python 3.

Also you can read why it is not working on Python 3 here.

UPD:

for using Python 3 you can try add code before using the lib:

import sys

if sys.version_info[0] >= 3:
    from urllib.request import urlretrieve
else:
    # Not Python 3 - today, it is most likely to be Python 2
    # But note that this might need an update when Python 4
    # might be around one day
    from urllib import urlretrieve

UPD2: urlretrieve import does not help)

Ivan Bryzzhin
  • 2,009
  • 21
  • 27
  • so how this line will change for Python 3: urllib.urlretrieve('http://audio.musicinformationretrieval.com/drum_samples/test/%s' % filename, filename=os.path.join(collection, filename)) – SubodhD Nov 18 '17 at 09:23
  • in best way you should not change it, because this is external lib, which should work with Python 2, just use Python 2. Also as I get already link to stackoverflow discussion about changes in urllib between Python's version, there is a suggetion to try... will add code to ansewer. – Ivan Bryzzhin Nov 18 '17 at 09:31
  • Ok. I'll install Python 2. The code update you have made is not working for me. I have tried already. Thanks for the help. – SubodhD Nov 18 '17 at 09:37