Bundling pygame into my addon

Hello everyone, I’m begining my journey in addon developement and I have been trying for the last week to bundle pygame into my addon.
If someone has done something similar, I would really appreciate some help :smiley:

1 Like

What steps did you try?

Maybe this will help:

Thank you very much for your reply.
When I do that, and then try to import pygame in my addon, I get a module not found error, then I added a line to add the module to the path

sys.path.insert(0, os.path.dirname(__file__))
import pygame

And I get the follwing error

Erreur
Un greffon que vous avez installé n’a pu se charger. Si le problème persiste, allez dans le menu Outils > Greffons et désactivez ou supprimez ce greffon.

Pendant le chargement de « <U+2068>test<U+2069> » :
<U+2068>Traceback (most recent call last):
  File "aqt.addons", line 247, in loadAddons
  File "C:\Users\spoto\AppData\Roaming\Anki2\addons21\test\__init__.py", line 19, in <module>
    import pygame
  File "C:\Users\spoto\AppData\Roaming\Anki2\addons21\test\pygame\__init__.py", line 92, in <module>
    from pygame.base import *  # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ModuleNotFoundError: No module named 'pygame.base'
<U+2069>

Since pygame is made of C files, I’m guessing it comes from that, but I do not understand how that is a problem.

Help is really apreciated :slight_smile:

I can’t reproduce this. Installing pygame to the add-on’s folder using this works for me with your code:
pip install pygame -t .

1 Like

Can’t package C modules in addons unless you’re running Anki from source.

That’s not true and I don’t think it’s @Times’s problem here. I maintain an add-on that bundles C modules: ZIM Reader - AnkiWeb

1 Like

It worked !!

I fixed it by running pip3.9 install pygame -t . instead of pip install pygame -t .

Thank you very much for your time.

1 Like

managed to run pygame in the add-on?

yes I did !

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