pythonプログラミング で楽譜作成| music21 ~エラー処理

pythonプログラミング で楽譜作成| music21 ~エラー処理

以下のようなエラーが発生した場合の処置方法↓

SubConverterException: Cannot find a path to the 'mscore' file at C:\Program_rep\001_python\music21\C:\Program Files\MuseScore 3\MuseScore.exe -- download MuseScore

事象

show関数を用いて楽譜をpng(画像データ)で出力しようとした際に生じたエラーです。

musescoreDirectPNGPathの環境パスが違っているようです。

環境パス

musescoreDirectPNGPathには MuseScore 3のパスが記載されているのですが、

「C:\Program_rep\001_python\music21\C:\Program Files\MuseScore 3\MuseScore.exe」

となっているためエラーになっているようです。

正しくは「C:\Program Files\MuseScore 3\bin\MuseScore3.exe」です。

ここを書き換えます。↓エラー内容


---------------------------------------------------------------------------
SubConverterException                     Traceback (most recent call last)
Cell In [16], line 2
      1 f = note.Note("C4")
----> 2 f.show()

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\music21\base.py:2888, in Music21Object.show(self, fmt, app, **keywords)
   2886 scClass = common.findSubConverterForFormat(regularizedConverterFormat)
   2887 formatWriter = scClass()
-> 2888 return formatWriter.show(self,
   2889                          regularizedConverterFormat,
   2890                          app=app,
   2891                          subformats=subformats,
   2892                          **keywords)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\music21\converter\subConverters.py:395, in ConverterIPython.show(self, obj, fmt, app, subformats, **keywords)
    392     scores = list(obj.scores)
    394 for s in scores:
--> 395     fp = helperSubConverter.write(s,
    396                                   helperFormat,
    397                                   subformats=helperSubformats,
    398                                   **keywords
    399                                   )
    401     if helperSubformats[0] == 'png':
    402         if not str(environLocal['musescoreDirectPNGPath']).startswith('/skip'):

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\music21\converter\subConverters.py:1138, in ConverterMusicXML.write(self, obj, fmt, fp, subformats, makeNotation, compress, **keywords)
   1133     defaults.author = savedDefaultAuthor
   1135 if (subformats is not None
   1136         and ('png' in subformats or 'pdf' in subformats)
   1137         and not str(environLocal['musescoreDirectPNGPath']).startswith('/skip')):
-> 1138     outFp = self.runThroughMusescore(xmlFp, subformats, **keywords)
   1139 elif compress:
   1140     archiveTools.compressXML(xmlFp,
   1141                              deleteOriginal=True,
   1142                              silent=True,
   1143                              strictMxlCheck=False)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\music21\converter\subConverters.py:972, in ConverterMusicXML.runThroughMusescore(self, fp, subformats, dpi, **keywords)
    968     raise SubConverterException(
    969         'To create PNG files directly from MusicXML you need to download MuseScore and '
    970         + 'put a link to it in your .music21rc via Environment.')
    971 if not musescorePath.exists():
--> 972     raise SubConverterException(
    973         "Cannot find a path to the 'mscore' file at "
    974         + f'{musescorePath} -- download MuseScore')
    976 if subformats is None:
    977     subformatExtension = 'png'

SubConverterException: Cannot find a path to the 'mscore' file at C:\Program_rep\001_python\music21\C:\Program Files\MuseScore 3\MuseScore.exe -- download MuseScore

パスの書き換え

envirnment.setでパスをセットします。

environment.set('musescoreDirectPNGPath', 'C:\Program Files\MuseScore 3\bin\MuseScore3.exe')

参考サイト