Bundling Numpy in an add-on

Is there a way to bundle numpy in an add-on so that it can be used as a dependency for another package? Currently struggling to get it to work.

2 Likes

Numpy is relatively cumbersome to bundle with add-on because it includes the C language.
Need to use the same Numpy wheel as the Python version of Anki. The latest Anki for desktop on Windows and Mac uses Python 3.9. Maybe numpy 2.0.2 is the last version that supports python 3.9. numpy·PyPI

e.g. The Numpy wheel for Python 3.9 on Windows is probably “numpy-2.0.2-pp39-pypy39_pp73-win_amd64.whl”. Put it in the add-on or download (or create your own Wheel) and unzip it then add the path to the sys.path. This explanation and code by developer Abdo will be helpful.

Note that Linux users often use the latest version of Python, not Anki version 3.9.
In this case it is necessary to identify their Python version and architecture. But Linux users are only a few percent so if it’s difficult you may want to exclude them from support.

Also in the future Anki may upgrade the Python version (I don’t know when that will be. Upgrade from Python 3.9.18 · Issue #4022 · ankitects/anki · GitHub). In this case the python 3.9 wheel will be broken so it will be necessary to update the wheel.

4 Likes

13 posts were merged into an existing topic: [Wiki] Bundling Python modules with add-ons

Created a wiki post here for organization and discussion:

1 Like

[Do you want me to move any of the posts from here over to there?]

2 Likes

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