9

运行时出现错误:

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 不再抱怨它们不可用。我在 Windows 7 上运行 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)?

4

2 回答 2

7

百合

我有同样的错误。我设法通过以下方式为 music21 配置 LilyPond:

  1. 将 LilyPond 文件夹移动到没有空格的路径(从C:\Program Files (x86)\LilyPond\usr\binC:\LilyPond\usr\bin)。我在 music21 代码中看到它在执行 lilypond 命令时没有在路径周围设置必要的配额,因此必须以这种方式解决问题。
  2. 在 music21 中创建配置文件并设置 lilypondPath

    us = environment.UserSettings()
    us.create()
    us['lilypondPath'] = 'C:/LilyPond/usr/bin/lilypond.exe'
    

    您可以检查它是否设置正确:

    print us['lilypondPath']
    
  3. 好吧,这可能不是必需的,但是在我尝试的过程中,我多次重新启动了所有内容,因此如果一切都无法立即运行,您可以在最后尝试一下。

肌肉分数

  1. 以防万一,将Musescore安装到没有空格的路径(
  2. 向环境添加了两次 musescore 路径(找到了这种设置环境变量的新方法),一次为"musescoreDirectPNGPath"

    environment.set("musescoreDirectPNGPath", "C:/MuseScore2/bin/MuseScore.exe")

    然后作为"musicxmlPath"

    environment.set("musicxmlPath", "C:/MuseScore2/bin/MuseScore.exe")

  3. 经过几次尝试、调试等,我了解到如果我们想使用 Musescore,传递文件名“.xml”扩展名而不是“.png”很重要:

    stream_name.show('musicalxml.xml')

    Musescore 无法打开 .png 文件,但可以打开 .xml 文件。

最后,我可以添加一些无需打开 lilypond 或 musescore 即可生成文件的代码。希望有人觉得它有用

百合:

# 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'])

肌肉:

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)并稍后重命名为我们想要的。

于 2015-06-13T18:06:01.353 回答
1

我能够设置带有空格的路径的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'

希望能帮助到你!

于 2017-09-29T20:01:55.810 回答