[yocto] BKM for Importing Python Modules

Burton, Ross ross.burton at intel.com
Thu Nov 30 02:47:43 PST 2017


Python functions in classes are executed by the Python that is executing
bitbake, which doesn't have access to the modules in the native sysroot
(and won't, as any compiled modules in there are linked against the native
python, not the host python).

You can solve this by either mandating python-cryptography on the host, or
writing a standalone script that is executed using nativepython (which is
the python built by python-native).

Ross

On 30 November 2017 at 00:09, <Aaron_Wright at selinc.com> wrote:

> I have a python function that I've added to PACKAGEFUNCS in a bbclass, and
> I want to use python-cryptography in that function. However, sys.path
> doesn't seem setup to allow this import. I'm curious to know the best known
> method for using python modules that are outside of  <LAYER>/lib directory.
> Should I just append STAGING_LIBDIR_NATIVE to sys.path?
>
> python do_stuff() {
>     import cryptography # <-- this fails
>
>     # Other stuff...
> }
>
> python () {
>     if (not bb.data.inherits_class("native", d) and
>         not bb.data.inherits_class("cross", d)):
>
>         d.appendVar("PACKAGEFUNCS", " do_stuff")
>         d.appendVarFlag(
>             "do_package",
>             "depends",
>             " python-cryptography-native:do_populate_sysroot")
> }
> --
> _______________________________________________
> yocto mailing list
> yocto at yoctoproject.org
> https://lists.yoctoproject.org/listinfo/yocto
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20171130/7afa17b0/attachment.html>


More information about the yocto mailing list