在python安装 music21后,需要关联 musescore 或 lilypond 才能可以用图形化的形式看到 乐谱。

因此 在安装 music21后,需要配置环境变量,yvivid 在 music21的官方 doc 没找到简单的指引,后来搜到相关信息,整理如下。

首先、在 python 中导入music21(安装可以 pip install music21实现):

from music21 import *

然后,查看环境变量有哪些:

>>>environment.keys()

['directoryScratch', 'lilypondPath', 'lilypondVersion', 'lilypondFormat', 'lilypondBackend', 
'musicxmlPath', 'midiPath', 'graphicsPath', 'vectorPath', 'pdfPath', 'braillePath', 'musescoreDirectPNGPath',
'showFormat', 'writeFormat', 'ipythonShowFormat', 'autoDownload', 'debug', 'warnings', 'localCorpusSettings',
'localCorporaSettings', 'manualCoreCorpusPath', 'localCorpusPath']

或者是

>>> us = environment.UserSettings()
>>> us.keys()
['directoryScratch', 'lilypondPath', 'lilypondVersion', 'lilypondFormat', 'lilypondBackend', 'musicxmlPath',
'midiPath', 'graphicsPath', 'vectorPath', 'pdfPath', 'braillePath', 'musescoreDirectPNGPath', 'showFormat',
'writeFormat', 'ipythonShowFormat', 'autoDownload', 'debug', 'warnings', 'localCorpusSettings',
'localCorporaSettings', 'manualCoreCorpusPath', 'localCorpusPath']

后续统一使用后者进行配置。

对于 lilypond的配置(路径请自行编写):

us['lilypondPath'] = 'C:/Program Files (x86)/LilyPond/usr/bin/lilypond.exe'

对于 musescore的配置:

us['musescoreDirectPNGPath'] = "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe"
us['musicxmlPath'] = "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe"

如果 keys()里面没有 相关配置,可以先set出相关配置项。

environment.set("musescoreDirectPNGPath", "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe")
environment.set("musicxmlPath", "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe")

最后,yvivid做个验证测试:

from music21 import *
littleMelody = converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#")
littleMelody.show()

作者:www.cnblogs.com/yvivid

参考文献:

1、http://web.mit.edu/music21/doc/usersGuide/usersGuide_08_installingMusicXML.html

2、https://stackoverflow.com/questions/25879764/creating-images-of-notes-in-music21

最新文章

  1. RAC 10.2.0.5,客户端登陆间断遭遇ORA-12545
  2. html5 formData上传 针对app端
  3. Js 关于console 在IE 下的兼容问题
  4. Bug Tracker 使用笔记(有图有真相)
  5. ADO.NET 实体框架 资料收集
  6. laravel笔记
  7. PHP- Windows无法在本地计算机启动Apache的解决方法
  8. 将你的Asp.NET应用程序嵌入到SharePoint
  9. android应用一(调用WebServices)
  10. Lua环境配置 windows + VS
  11. Apache Spark1.1.0部署与开发环境搭建
  12. 架构之微服务(etcd)
  13. SpringBoot添加对Log4j2的支持
  14. 安装python-ldap fatal error: lber.h: No such file or directory
  15. libgdx游戏引擎教程
  16. Java多线程之ThreadLocal总结2
  17. 可能是目前最完整的前端框架 Vue.js 全面介绍
  18. [HNOI2013]题解
  19. 全面理解Java内存模型(JMM)及volatile关键字(转)
  20. ss - float浮动模块的高度问题 解决方案

热门文章

  1. varnish与squid的比较
  2. phpcms文件结构
  3. asp.net5中程序根目录的获取
  4. MongoDB-2.6.0 (OpenLogic CentOS7.2)
  5. 绿盟堡垒机云服务(vSAS-H)
  6. Python __builtin__模块
  7. LeetCode Remove Duplicates from Sorted List 删除有序链表中的重复结点
  8. HDU 1114 Piggy-Bank 猪仔储钱罐(完全背包)
  9. linux 命令——10 cat (转)
  10. JS每点击一次添加多少条数据