NameError: name 'request' is not defined in python 3

NameError: name 'request' is not defined in python 3

我正在尝试 运行 来自以下站点的基本特征提取代码:
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'

请帮我解决这个问题。

看来你应该使用 Python 2 而不是 3。在 instruction 到 stanford_mir 中有一行:

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

您还可以阅读为什么它在 Python 3 here.

上不起作用

更新:

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

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 导入没有帮助)