Using custom python modules in classes and functions

Marek S?omiany

Hello everyone,

I am working on creating a custom class (basically own image signing) that will be using a client's python module, but to simplify I'll use as an example a python3 module Magic as it behaves in exactly the same way. I'm working on dunfell.

So basically in recipe I am using depends to add the module and it works in example like that:

inherit python3native
DEPENDS += "python3-magic-native"
        python3 ${S}/

and in importing magic works fine, but when I'm trying to import magic in python function, bitbake-style python functions or in anonymous python functions it fails to find the module.
as an example that do NOT work:
def foo(d):
    import magic
    mime = magic.Magic(mime=True)
    return "foo"

python do_bar () {

Neither it works in do_bar nor in foo as shown above. Always ends up with:
Exception: ModuleNotFoundError: No module named 'magic'

I have also tried to set variable:
PYTHON_SITEPACKAGES_DIR = "${WORKDIR}/recipe-sysroot/usr/lib/python3.8/site-packages"
but it does nothing in my case.

Can you help me with this?

Kind Regards,
Marek Slomiany

Join { to automatically receive all group messages.