Python 从Music21保存图像文件

Python 从Music21保存图像文件,python,music21,music-notation,Python,Music21,Music Notation,我已经下载了很多.krn文件,我想用music21将它们转换成图像——PNG或JPG。我试过这个: 当我这样做时: from music21 import * op = krnfile s = converter.parse(op) s.show() 我在使用的Jupyter笔记本中看到了一个很棒的图像文件,但当我尝试以编程方式保存该文件时,如下所示: s.write(fp = 'outputfile.png', fmt = 'png') 它说: Music21ObjectExcept

我已经下载了很多.krn文件,我想用music21将它们转换成图像——PNG或JPG。我试过这个:

当我这样做时:

from music21 import *   
op = krnfile
s = converter.parse(op)
s.show()
我在使用的Jupyter笔记本中看到了一个很棒的图像文件,但当我尝试以编程方式保存该文件时,如下所示:

s.write(fp = 'outputfile.png', fmt = 'png')
它说:

Music21ObjectException: cannot support showing in this format yet: png
这似乎有点奇怪,因为它显然能够在笔记本上显示一个图像

看起来我可以从中使用
LilypondConverter.createPNG(fileName=None)
,但是否需要安装Lilypond?我已经安装了MuseScore2,当我调用
s.show()
时会打开它

非常感谢! Alex

如果使用n.show('lily.png'),它应该在某处创建一个临时png文件。尝试使用它,图像可能会打开


很抱歉,我还不太了解,我希望它能有所帮助。

尝试
fmt='musicxml.png'
——您需要将其转换为musicxml,然后让助手转换器使用musescore将其从那里转换为png。或者对于lilypond(
fmt='lily.png'
),它确实有帮助,尝试在下次我投票时加入一些它工作的例子无论如何欢迎来到SO
n.show('lily.png')
抛出与Op相同的错误。