NameError:name' request'未在python 3

时间:2017-11-18 09:07:03

标签: python python-3.x urlretrieve

我正在尝试从以下网站运行基本功能提取代码:
musicinformationretrieval
当我尝试运行以下代码行时:

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

它显示以下错误消息:

---------------------------------------------------------------------------
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'

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

看起来你应该使用3的Python 2.在instruction到stanford_mir有行:

  
      
  1. 如果您是全新的,最简单的解决方案是下载并安装Anaconda for Python 2 (2.7),而不是Python 3.
  2.   

此外,您可以阅读为什么它不适用于Python 3 here

UPD:

使用Python 3,您可以在使用lib之前尝试添加代码:

 @Override
   protected void onPostExecute(JSONArray jsonArray) {

 super.onPostExecute(jsonArray);
            System.out.println(wallPaperAdapter);
            wallPaperAdapter.notifyDataSetChanged();
            System.out.println(wallpaperList.size());
        }

UPD2: urlretrieve import没有帮助)