music21 write() function giving AttributeError: 'Rest' object has no attribute 'pitches' on python 3.9.1 and music21 version 7
music21 write() function giving AttributeError: 'Rest' object has no attribute 'pitches' on python 3.9.1 and music21 version 7
我正在使用在此要点上找到的代码:https://gist.github.com/aldous-rey/68c6c43450517aa47474#file-transposer-py 当我 运行 我拥有的 MIDI 脚本(包括作者的脚本)时,我得到了错误
AttributeError: 'Rest' object has no attribute 'pitches'
这是很旧的代码,我不得不修改一下以适应 python 3.9.1。我目前使用的是最新的 music21 版本 7。write() 函数是否有任何更改会破坏此代码?
编辑:这是完整的回溯:
Traceback (most recent call last):
File "C:\Users\username\path\to\transposer.py", line 28, in <module>
newscore.write('midi',newFileName)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\stream\base.py", line 328, in write
return super().write(fmt=fmt, fp=fp, **keywords)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\base.py", line 2665, in write
return formatWriter.write(self,
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\converter\subConverters.py", line 1147, in write
mf = midiTranslate.music21ObjectToMidiFile(obj, **midiTranslateKeywords)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\midi\translate.py", line 260, in music21ObjectToMidiFile
return streamToMidiFile(music21Object, addStartDelay=addStartDelay)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\midi\translate.py", line 2559, in streamToMidiFile
midiTracks = streamHierarchyToMidiTracks(s,
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\midi\translate.py", line 2443, in streamHierarchyToMidiTracks
subs.stripTies(inPlace=True, matchByPitch=False)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\stream\base.py", line 7283, in stripTies
endMatch = updateEndMatch(n)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\stream\base.py", line 7166, in updateEndMatch
and nLast is not None and len(nLast.pitches) == len(nInner.pitches)):
AttributeError: 'Rest' object has no attribute 'pitches'
是的,这是版本 7 中的一个错误,但多亏了这份报告,我已经打开 pull request 来解决这个问题。
今年秋天可能会发布错误修复版本,或者您也可以在 PR 合并后从开发版本中提取,例如pip uninstall music21
和 pip install git+https://github.com/cuthbertLab/music21.git
。再次感谢您的举报!
我也遇到了同样的问题。在我的例子中,我将 music21 的版本降级到 6.7.1 版本,它开始像魅力一样工作。 :)
pip install --upgrade music21==6.7.1
我正在使用在此要点上找到的代码:https://gist.github.com/aldous-rey/68c6c43450517aa47474#file-transposer-py 当我 运行 我拥有的 MIDI 脚本(包括作者的脚本)时,我得到了错误
AttributeError: 'Rest' object has no attribute 'pitches'
这是很旧的代码,我不得不修改一下以适应 python 3.9.1。我目前使用的是最新的 music21 版本 7。write() 函数是否有任何更改会破坏此代码?
编辑:这是完整的回溯:
Traceback (most recent call last):
File "C:\Users\username\path\to\transposer.py", line 28, in <module>
newscore.write('midi',newFileName)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\stream\base.py", line 328, in write
return super().write(fmt=fmt, fp=fp, **keywords)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\base.py", line 2665, in write
return formatWriter.write(self,
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\converter\subConverters.py", line 1147, in write
mf = midiTranslate.music21ObjectToMidiFile(obj, **midiTranslateKeywords)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\midi\translate.py", line 260, in music21ObjectToMidiFile
return streamToMidiFile(music21Object, addStartDelay=addStartDelay)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\midi\translate.py", line 2559, in streamToMidiFile
midiTracks = streamHierarchyToMidiTracks(s,
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\midi\translate.py", line 2443, in streamHierarchyToMidiTracks
subs.stripTies(inPlace=True, matchByPitch=False)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\stream\base.py", line 7283, in stripTies
endMatch = updateEndMatch(n)
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\music21\stream\base.py", line 7166, in updateEndMatch
and nLast is not None and len(nLast.pitches) == len(nInner.pitches)):
AttributeError: 'Rest' object has no attribute 'pitches'
是的,这是版本 7 中的一个错误,但多亏了这份报告,我已经打开 pull request 来解决这个问题。
今年秋天可能会发布错误修复版本,或者您也可以在 PR 合并后从开发版本中提取,例如pip uninstall music21
和 pip install git+https://github.com/cuthbertLab/music21.git
。再次感谢您的举报!
我也遇到了同样的问题。在我的例子中,我将 music21 的版本降级到 6.7.1 版本,它开始像魅力一样工作。 :)
pip install --upgrade music21==6.7.1