0

I'm trying to use abjad and lilypond in pycharm to generate music for a school project. However, after getting abjad and lilypond installed, I can't seem to get abjad to work with lilypond.

I've tried following the instructions on the lilypond website. I read something about configuring my run configuration but can't seem to get it to work. I don't know how to add the path for the virtualenv in PyCharm.

I just get this in the run window "/bin/sh: lilypond: command not found" when I run some example code.

notes = [abjad.Note("ds'16"), abjad.Note("cs'16"), abjad.Note("e'16"), abjad.Note("c'16")]  
container = abjad.Container(notes)  
abjad.show(container)

EDIT 1: I tried adding /LilyPond.app/Contents/Resources/bin/lilypond to Interpreter paths in my Project Interpreter still with no success.

EDIT 2: That's what my interpreter paths look like: https://i.stack.imgur.com/ec1E0.jpg

Jin Lee
  • 3,194
  • 12
  • 46
  • 86
Joshua
  • 11
  • 3
  • i believe you need to go to your pycharm settings/preferences and change your project interpreter to your virtualenv. have you seen this? https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html – spinodal Jul 08 '19 at 22:47
  • The project interpreter is already the virtualenv – Joshua Jul 08 '19 at 22:52
  • hm we may be getting mixed up. the interpreter path is the location of the python executable, not the location of the lilypond executable. anyway that is probably not the issue if `abjad` is working. check that the location of the lilypond executable is in your path. if not they try `export PATH="$PATH:/Applications/LilyPond.app/Contents/Resources/bin/"` – spinodal Jul 08 '19 at 22:58
  • tried that in the venv terminal in pycharm and in the os terminal since I'm not familiar with this I just tried both, still nothing – Joshua Jul 08 '19 at 23:07

1 Answers1

0

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).
Owen S.
  • 7,665
  • 1
  • 28
  • 44