Header logo.
Small Hallucinations
HomeArchiveTagsAboutFeed

Fixing addon bugs for Anki 23

I've been using Anki for years. Anki has recently changed its version numbers to year.month. From version 23.10, FSRS algorithm is implemented for scheduling reviews. Without thinking too much, I upgraded to the latest version.

Not surprisingly, this upgrade broke a few addons on my computer:

  1. Syntax Highlighting for Code
  2. Mini Format Pack
  3. Zoom 2.1; and
  4. Customize Keyboard Shortcuts

Fixing them was easier than I had thought.


When you start Anki, you are greeted with this alert if there's a bug in an addon.

By clicking “copy debug info”, you'll have some clue around how to move forward.

This is the first clue for fixing Syntax Highlighting for Code:

Anki 23.12.1 (1a1d4d54)  (ao)
Python 3.9.15 Qt 6.5.3 PyQt 6.5.3
Platform: macOS-13.0.1-arm64-arm-64bit
When loading Syntax Highlighting for Code:
Traceback (most recent call last):
# ...
  ".../Application Support/Anki2/addons21/1463041493/consts.py", line 22, in 
    addon_path = os.path.dirname(__file__).decode(sys_encoding)
AttributeError: 'str' object has no attribute 'decode'

By following this path, we can fix this bug by simply changing line 22 into something like this:

anki21 = version.startswith("2.1.") or version.startswith("23")

The same change fixed Mini Format Pack too.


The reason why Zoom 2.1 stopped working is it imports Qt5 when Anki is using Qt6 now.

Long story short, go to the addon folder and change the import section in __init__.py to this:

from PyQt6.QtCore import Qt
from PyQt6.QtGui import QKeySequence, QAction
from PyQt6.QtWidgets import QMenu

While debugging, you'll need to check the actual value of variables. The way I did it is: dump a value to JSON, create a new error that includes this JSON and raise this error.

The downside is you have to quit Anki and start it again over and over. Luckily it didn't take me too much time to fix the first three addons.

I only scratched the surface of Customize Keyboard Shortcuts as the logic inside it is a bit complicated. If you want to fix it, here's something you can start with:

The constant Qt.Key_Enter is no longer valid. You'll need to use Qt.Key.Key_Enter.