Add support for dependencies in addons

It will be very cool to have (at least) available pip inside Anki, or if Anki will install requirements.txt file inside addons.

The best will be to create virtual envs for every addon, so their dependencies will not conflict. But I’m unsure how would you activate many venvs inside one process.

At now, addons must vendor dependencies, which is terrible when you have such things as pip. This produces a lot of bugs just because.

There is also discussion on this theme on Reddit, but I can’t include links(

Vendoring is usually as simple as doing the following for me:

  • pip install -r requirements.txt -t src/vendor.
  • Adding src/vendor to sys.path, or maybe using a modified version of the snippet here where you don’t mess around with sys.modules/sys.path, and instead just use the object you get from importlib.util.module_from_spec to avoid conflicts. (I usually just append/insert to sys.path, and have not tested my suggestion yet)

It becomes a real pain when C extensions are involved. For this case, I imagine a native solution from Anki’s side can get quite complicated and will be probably fragile.
See this for an example of how I recently went about bundling non-pure python dependencies for multiple platforms and Anki versions.

1 Like

Still, it’s much more complicated than just `pip install package’. Instead of spending time on the vendor, developers should spend their time only on programming.

Anyway, I opened this topic as a feature request because on GitHub it’s not allowed:
image

I’ve already done vendoring in my addon, but I don’t think it’s the right solution when `pip’ exists.