The first problem you ran into is, out of the box, the MacOS Lilypond app does not expose its underlying command-line tool in a way that is easily accessible by other apps. The second part is that, even if you fix this problem, it's not super-obvious how to get the fix into PyCharm. Fortunately, both problems can be solved.
First, to explain the error. The error:
/bin/sh: lilypond: command not found
indicates that a shell script is trying to run lilypond
without any particular location of the tool specified. MacOS will look at your PATH
environment variable in that case to try to locate it.
Second, to correct a wrong path you were going down: do not use Interpreter Path for this. The only use of that is to tell PyCharm where the Python interpreter lives; you cannot use it to inform abjad where Lilypond lives. For that latter task, PATH
is going to be your best bet.
There are a few ways to fix this, but the gist is: you need to update your PATH
with some directory that contains the tool – but you also need to update it in a way where scripts launched by PyCharm pick up the updated PATH
.
Generally, I do my PATH
hacking in ~/.bash_profile
, since Bash is the default shell in MacOS, and this "script" gets loaded every time I start a Terminal (at least for recent versions of OS X/MacOS). To this script, add a line that looks something like this (making a backup of the script first!):
export PATH="$PATH:/Applications/LilyPond.app/Contents/Resources/bin/"
and save your change. Once you do this, if you launch a new Terminal window, you should be able to run lilypond
and see Lilypond usage printed out.
Once you have that set up, I believe you merely need to quit and relaunch PyCharm, and it should pick up the new PATH
. (Failing that, try logging out and in again.) In my version of PyCharm, I check that PATH
is correct by going to the preferences, finding the settings "Build, Execution, Deployment > Console > Python Console", looking for a text field called "Environment Variables" (of which PATH
is one), clicking on a "..." button just to the right of the text field to see details, making sure "Include parent environment variables" is checked, and then clicking on a "Show" link next to that checkbox to have PyCharm pop up a dialog with all of the environment variables it's passing along when it runs Python console operations. PATH
should be listed there, and your Lilypond path should be included in its value.
I don't know about you, but I find it distasteful to have to put the guts of MacOS apps directly in my PATH
like this, so there are a couple of other solutions I'll mention for completeness:
- Use symbolic links to make the tool appear in a directory that's already in your
PATH
. Using a Terminal, cd
to the directory you want (I like ~/bin
for my personal tools, a directory which I created myself and added to my PATH
a long time ao), and create a symbolic link to Lilypond thus: ln -s /Applications/LilyPond.app/Contents/Resources/bin/lilypond .
.
- You can also install a pure command-line version of Lilypond into
/usr/local/bin
using Homebrew, a tool I find invaluable for wrangling Unix applications in MacOS. /usr/local/bin
, so far as I know, should already be on your PATH
(and if not, it's good to add it!). The problem with this approach – apart from multiple Lilypond installations running around on your machine, its version of Lilypond tends to lag a bit, which may cause problems with Abjad down the road. (It's currently on 2.18.2, which is the latest stable version).