Anki Forums

Attaching debugger in PyCharm for addon development

How do you all typically setup PyCharm, so that you can attach the debugger when developing an addon? I was able to get it working, but it felt a little clunky, so wanted to see if there was an easier way. These were the steps that I used:

  1. clone and build anki from source using steps outlined README.development

Within PyCharm

  1. Open -> addon in PyCharm as a project.
    • addon the directory containing addon that you’re working on.
  2. Open -> anki -> Attach
    • anki is the directory of version built from source in 1.
  3. Add new run configuration. Here is mine (sorry wasn’t allowed to upload an image to the forum since I’m new, but linked to imgur along with key params below).
    • Script Path: ~/PycharmProjects/anki/qt/runanki
    • Parameters: -b ~/PycharmProjects/addon/profile
      • Creates a new profile, so doesn’t mess up real Anki profile if you are an Anki user
    • Interpreter: ~/PycharmProjects/anki/pyenv/bin/python
      • Initally I didn’t realize that anki creates its own python environment when you build it from source. You need to use that interpreter to start anki in the run configuration.
  4. ln -s ~/PycharmProjects/addon/src ~/PycharmProjects/addon/profile/addons21
    • symlink or copy the addon source location to the dev profile’s addons21 directory.

Which OS are you on? And are you running everything on a host OS or are you using a VM?

On mac running on host OS at the moment (open to using docker too though).

I’m on windows but I hope pycharm works similarly on both systems.
Looks very similar to my setup, I’m using my own python environment though and have not had any problems with it so far.
I don’t really understand your fifth step, never had to do this. I marked anki’s pylib and qt directories as source and attached the directory to my project which works fine for me:

@Humorloos Step 5. was because anki expects addons to be in its addons21 directory, so I just symlinked the addon that I was working on to anki's addons21 directory. I think the other option would be to move the addon to that directory. Without that step the addon didn’t show up in the Tools -> Add-ons menu.