How to Manage Python Dependencies for Anki Add-ons?

Hello, I’m developing an Anki add-on that relies on the google-auth and google-auth-oauthlib Python libraries. I’m facing issues with Anki finding these libraries, even after following these steps:

  1. Installing Directly into Anki’s ‘lib’ Folder: I’ve used Anki’s associated pip to install the libraries directly into Anki’s main lib directory (e.g., C:\Program Files\Anki\lib).
  2. Dynamic Importing: I’ve tried dynamically loading the modules from within my add-on’s lib folder using importlib.util.

Despite these attempts, I’m still encountering “ModuleNotFoundError” errors. Here’s an example error:

ModuleNotFoundError: No module named 'google.auth'

  • Anki appears to strongly isolate its Python environment, preventing my add-on from accessing the required libraries.
  • This behavior persists even when using standard import mechanisms and installing the libraries into Anki’s core directory.
  1. Is there a recommended Anki-specific way to package Python dependencies with add-ons?
  2. Are there configuration options or techniques to influence how Anki searches for add-on modules?
  • I’ve scoured Anki’s documentation but haven’t found definitive guidance on add-on dependency management.
  • Any insights or suggestions from experienced Anki developers would be greatly appreciated!
3 Likes

Does this work for you?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.