Uploading addon: what about dependencies?

Hello,

on morning today, I posted an announce for my new addon.
I wanted to publish it on ankiweb but sadly, I am not sure how I should do it.
My problem is not on how to create the zipfile but on what is the best way to provide python dependencies.

What’s the recommended way to do it ?

1 Like
2 Likes

You can install the lib inside your addon folder using cmd

example:
cd C:\Users\eros\AppData\Roaming\Anki2\addons21\11112222

assuming the libg is called PyMuPDF, then do this in cmd.
pip install --target=./vendor PyMuPDF

compress this along with init.py manifest.json if you have it and meta.json

it will all be in zip format, for example: myaddon.zip and then you rename it to myaddon.ankiaddon

then just go to the website below to leave your addon there, remembering to put the correct version too
https://ankiweb.net/shared/upload

in the addon code you have to remember to put the lib folder there

addon_path = os.path.dirname(__file__)
vendor_path = os.path.join(addon_path, "vendor")

if vendor_path not in sys.path:
sys.path.insert(0, vendor_path)
2 Likes

keep in mind that you need to bundle the different module versions for each platform, and ensure you’re bundling a version that is compatible with the version of Python Anki is packaged with.
A simple pip install --target=./vendor PyMuPDF may not suffice. YMMV

3 Likes

Actually, my answer was based on the last addon I released.
It also has the option to download the lib, but I thought it would be better to leave it inside the addon and compress it with the rest of the code.

https://ankiweb.net/shared/info/16097657

Problem is I am using pyCharm which hides many things (and I am not really a python dev)

I don’t consider myself a developer either, just a curious person who likes to do this as a hobby.
I ask questions to AI (aistudio, grok, claude, chatgpt etc.), so maybe they can help you too.
Put the code there and ask them what you want to do, be specific and if it starts to go crazy, open another tab and start from scratch.
Thanks to AI I was able to make several addons.

If you have the whole code like the Github repository it may help. If you are not using Github please try to write names of modules you are using other than the python standard library and Anki’s aqt module.
If you are using many modules I think it is difficult for add-on to support cross-platform work (technically possible but cumbersome, and fragile by Anki update). If so an add-on made on Windows will work only on Windows.

Modules written in pure Python with no dependencies are relatively easy to incorporate into an add-on. So I recommend that you keep your code as Python-only as possible, and use modules that are used by Anki instead.
e.g. if you are using Pillow(PIL) to generate png I recommend using Anki’s built-in PyQt6 to generate images instead. PyQt is a module for creating GUI so it can be used to create most GUI and image related things.

1 Like