[英]NameError: name 'request' is not defined in python 3
我正在尝试从以下站点运行基本功能提取代码:
音乐信息检索 。
当我尝试运行以下代码行时:
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 insteed3。在stanford_mir的指令中有以下代码行:
- 如果您是全新手,最简单的解决方案是下载并安装适用于Python 2(2.7)的Anaconda ,而不是Python 3。
您也可以在这里阅读为什么它不能在Python 3上运行。
UPD:
对于使用Python 3,您可以在使用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导入无济于事
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.