运行时出现错误:
from music21 import *
n1 = note.Note('C4', quarterLength=1)
n2 = note.Note('A4', quarterLength=1)
s = stream.Stream()
s.append(n1)
s.append(n2)
s.show('lily.svg')
Traceback (most recent call last):
File "C:\Python34\test.py", line 7, in <module>
s.show('lily.svg')
File "C:\Python34\lib\site-packages\music21\base.py", line 2206, in show
return formatWriter.show(self, regularizedConverterFormat, app=app, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 277, in show
returnedFilePath = self.write(obj, fmt, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 245, in write
conv = lily.translate.LilypondConverter()
File "C:\Python34\lib\site-packages\music21\lily\translate.py", line 147, in __init__
self.setupTools()
File "C:\Python34\lib\site-packages\music21\lily\translate.py", line 177, in setupTools
versionString = versionString.split()[-1]
IndexError: list index out of range我已经安装了scipy和mathplotlib,所以music21不会再抱怨它们不可用了。我在Windows7上运行Python 3.4。
如果我使用s.show('musicxml.png')来获取我的图像,我会得到错误:
Traceback (most recent call last):
File "C:\Python34\test.py", line 7, in <module>
s.show('musicxml.png')
File "C:\Python34\lib\site-packages\music21\base.py", line 2206, in show
return formatWriter.show(self, regularizedConverterFormat, app=app, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 147, in show
returnedFilePath = self.write(obj, fmt, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 637, in write
fp = self.runThroughMusescore(fp, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 606, in runThroughMusescore
elif not os.path.exists(musescoreFile):
File "C:\Python34\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: can't specify None for path argument我必须做什么才能得到图片(最好是svg)?
发布于 2015-06-14 02:06:01
LILYPOND
我也犯了同样的错误。我已经设法通过以下方式为music21配置了LilyPond:
C:\Program Files (x86)\LilyPond\usr\bin移至C:\LilyPond\usr\bin)。我在lilypond代码中看到,在执行way.us = environment.UserSettings() us.create() us‘’lilypondPath‘=’C:/‘lilypondPath/usr/bin/lilypond.exe’
您可以检查是否设置正确:
print us'lilypondPath'
MUSESCORE
"musescoreDirectPNGPath"environment.set("musescoreDirectPNGPath", "C:/MuseScore2/bin/MuseScore.exe")然后作为"musicxmlPath"environment.set("musicxmlPath", "C:/MuseScore2/bin/MuseScore.exe")
stream_name.show('musicalxml.xml')
Musescore无法打开.png文件,但它可以打开.xml文件。
最后,我可以添加一些无需打开lilypond或musescore即可生成文件的代码。希望有人觉得它很有用
LILYPOND:
# music21object - stream or score or any object that can be showed
conv = music21.converter.subConverters.ConverterLilypond()
scorename = 'myScoreName'
filepath = 'C:/path/to/musical_scores/' + scorename
conv.write(music21object, fmt = 'lilypond', fp=filepath, subformats = ['pdf'])MUSESCORE:
from music21.converter.subConverters import ConverterMusicXML
conv_musicxml = ConverterMusicXML()
scorename = 'myScoreName.xml'
filepath = 'C:/path/to/musical_scores/' + scorename
out_filepath = conv_musicxml.write(music21object, 'musicxml', fp=filepath, subformats=['png'])注意,scorename有'.xml‘扩展名。
遗憾的是,它不会将文件保存在指定的文件路径中。Musescore将"-1“添加到文件名中,但可以获得更改后的文件路径(如上面代码中的out_filepath ),并在稍后重命名为我们想要的名称。
发布于 2017-09-30 04:01:56
我可以用一个带空格的路径来设置musescore。最重要的是要确保使用反斜杠。我是这样做的:
# Create the user environment for music21
us = m21.environment.UserSettings()
us['musicxmlPath'] = 'C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe'
us['musescoreDirectPNGPath'] = 'C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe'希望它能帮上忙!
https://stackoverflow.com/questions/25879764
复制相似问题