Cannot get Anki 2.1 lilypond add-on to work

I installed the lilypond add-on. I tried to display a card with Anki 2.1.15 and got a bug report. So I updated to Anki 2.1.22, and now lilypond code won’t compile at all – I get the text to show as entered.

I’m on a Win 10 Desktop PC. Lilypond is in my path. Anki 2.0 version of this add-on worked just fine.

Here’s what Anki 2.1.15 said when trying to display lilypond:

Anki 2.1.15 (442df9d6) Python 3.6.7 Qt 5.12.1 PyQt 5.11.3
Platform: Windows 10
Flags: frz=True ao=True sv=1

Caught exception:
File “aqt\progress.py”, line 72, in handler
File “aqt\clayout.py”, line 306, in _renderPreview
File “anki\cards.py”, line 120, in q
File “anki\cards.py”, line 137, in _getQA
File “anki\collection.py”, line 589, in _renderQA
File “anki\hooks.py”, line 39, in runFilter
File “C:\Users\immo\AppData\Roaming\Anki2\addons21\123418104\lilypond.py”, line 243, in mungeFields
match.group(), _imgLink(col, match.group(2), _lyFromHtml(match.group(3)))
File “C:\Users\immo\AppData\Roaming\Anki2\addons21\123418104\lilypond.py”, line 195, in _imgLink
err = _buildImg(col, ly, fname)
File “C:\Users\immo\AppData\Roaming\Anki2\addons21\123418104\lilypond.py”, line 162, in _buildImg
lyfile.write(ly.decode(“utf-8”))
File “C:\Program Files\Python36\lib\encodings\cp1252.py”, line 19, in encode
<class ‘UnicodeEncodeError’>: ‘charmap’ codec can’t encode character ‘\u017c’ in position 366: character maps to

1 Like

Can you create a simple example that works, e.g. [lilypond]a c a b[/lilypond]?

That card is quite complex and it looks like it’s having a problem with the lyrics, specifically when it encounters ż.

I would also suggest that you make sure the card has plain text only, i.e., no formatting. Try pasting that lilypond snippet as plain text into a new card.

See this article for help on how to do that:

1 Like

I just checked: my example works as long as it has only ASCII characters. When I add an umlaut (ä) to the lyrics, the respective character is just omitted. When I add the non-Western European ż, I get the above mentioned error.

Furthermore, after receiving the error message, even the most simple lilypond code won’t compile anymore.

I also checked whether the problem lies in lilypond itself, but outside of Anki it compiles just as expected.

I think for Anki, which is primarily a language-learning tool, supporting unicode is essential in any add-on. As I already said, it used to work with Anki 2.0.