Macmusic21にMusescore・Lilypondのパスを通す
pythonで音楽情報処理をやる定番ライブラリのmusic21に,MusescoreとLilypondのパスを通す設定方法のメモです。
環境
macOS 11.4 Big Sur (M1)
python 3.8.2
music21 v6.1.0
lilypond v2.20.0
museScore 3 v3.6.2
見やすさ重視で関数化しました。
code:python
import music21 as m2
# ファイルパスとLilypondのバージョン。環境に応じて変えてください
musescorePath = '/Applications/MuseScore 3.app/Contents/MacOS/mscore'
lilypondPath = '/Applications/LilyPond.app/Contents/Resources/bin/lilypond'
lilypondVersion = '2.20.0' # 念の為指定しておく
def initMusic21Path():
us = m2.environment.UserSettings()
# us.create() # これはその環境で一度だけ実行すればいい。2回目以降はエラーになる
us'musicxmlPath' = musescorePath
us'musescoreDirectPNGPath' = musescorePath
us'lilypondPath' = lilypondPath
us'lilypondVersion' = lilypondVersion
us'midiPath' = '/System/Applications/QuickTime Player.app'
print("settings:")
print("\tmusicxmlPath: ", musescorePath)
print("\tmusescoreDirectPNGPath: ", musescorePath)
print("\tlilypondPath:", lilypondPath)
print("\tlilypondVersion:", lilypondVersion)
if __name__ == '__main__':
initMusic21Path()
Windows環境と異なる点は,museScore,Lilypondはappの中の実行ファイルまでパスを通す点かと。
museScoreはdmgからインストールする際にApplicationフォルダにコピーされますが,Lilypondは手動でApplicationフォルダに移動する必要があります.
ちなみに,パスさえ正常に通せればApplicationディレクトリじゃなくても大丈夫です.
注意
Macの場合Lilypondのコマンドライン版プログラムはLilyPond.app/Contents/Resources/bin/lilypondです.
LilyPond.app/Contents/MacOS/lilypondはGUI版のLilypondで,これにパスを通すと正常に動きません.
WindowsのときはLilypondのバージョンを正しく設定しないとパスが通っても動かなかったため,Macでも念のため設定しておきます.
#music21 #python