1

I'm having a very hard time trying to find an example of building in a custom python module into Yocto (more specifically Xilinx's Petalinux) that will install into the python site-packages directory so I can write Python scripts on-target using my module.

This is what I have so far:

Directory tree

(in project-spec/meta-user/recipes-apps)

├── foo-python
    ├── files
    │   └── foo-python.py
    └── foo-python.bb

foo-python.bb

#
# This file is the foo-python recipe.
#

SUMMARY = "Simple foo-python application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://foo-python.py"

RDEPENDS:${PN} = "python3-core"

S = "${WORKDIR}"

do_install() {
       install -d ${D}${PYTHON_SITEPACKAGES_DIR}/${PN}
       install -m 0644 foo-python.py ${D}${PYTHON_SITEPACKAGES_DIR}/${PN}/
}

FILES_${PN} += "${PYTHON_SITEPACKAGES_DIR}/${PN}/*"

Error

When I bitbake my recipe (Petalinux-build), I get the following error:

NOTE: Executing Tasks ERROR: foo-python-1.0-r0 do_package: QA Issue: foo-python: Files/directories were installed but not shipped in any package:

/foo-python

/foo-python/foo-python.py

Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install. foo-python: 2 installed and not shipped files. [installed-vs-shipped] ERROR: foo-python-1.0-r0 do_package: Fatal QA errors found, failing task.

  1. I apologize in advance, I'm only familiar with Petalinux, and don't know where Petalinux ends, and Yocto/Bitbake overlaps.
  2. I can find examples online of how to add python modules from open-embedded layers, but I can't find a single example of adding a custom python module as installable python into site-packages.
4
  • Which release are you using: dunfell, kirkstone or scarthgap? Commented Aug 27, 2024 at 19:15
  • It's Petalinux 2022.1, so let's say Kirkstone. Commented Aug 27, 2024 at 21:19
  • You need to fix your FILES_${PN} += "${PYTHON_SITEPACKAGES_DIR}/${PN}/*", it should be: FILES_${PN} += "${D}${PYTHON_SITEPACKAGES_DIR}/${PN}/* Commented Aug 28, 2024 at 6:19
  • This question is similar to: How do I add more python modules to my yocto/openembedded project?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Aug 29, 2024 at 8:17

2 Answers 2

2

You can add inherit setuptools3 to the recipe and create a setup.py to do the installation. An example can be:

"""A setuptools based setup module.

See:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
https://github.com/pypa/sampleproject
"""

# Always prefer setuptools over distutils
from setuptools import setup, find_packages


setup(
    name="foo-python",

    # Package info
    packages=["foo-python"] + ["foo-python." + pkg for pkg in find_packages("foo-python")],
    package_data={"foo-python": ["*.py"]},
    python_requires=">=3.7, <4",
    entry_points={
        "console_scripts": [
            "foo = foo-python.main:main",
        ],
    },
)

And the recipe can be:

#
# This file is the foo-python recipe.
#

SUMMARY = "Simple foo-python application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://src"

RDEPENDS:${PN} = "python3-core"

S = "${WORKDIR}"
inherit setuptools3

The setup.py should be residing with your source code so bitbake can find and use it. Your directory structure can be similar to:

├── foo-python
    ├── files
    │   └── src
    │       ├── foo-python.py
    │       └── setup.py
    └── foo-python.bb
Sign up to request clarification or add additional context in comments.

3 Comments

This is probably the best and most "right" way of doing it. Instead of installing the files into the site-packages directly, let setuptools do it. I created the setup.py file and can install my package on the host machine, but I'm having trouble writing the bitbake recipe to do this in Yocto. Do you have one handy?
I have updated the answer above and provided a recipe.
To find more example recipes, do grep -Iri inherit setuptools3 inside meta-poky or meta-oe.
0

Try:

FILES:${PN} += "${PYTHON_SITEPACKAGES_DIR}/${PN}/*"

or

FILES:${PN} += "${D}${PYTHON_SITEPACKAGES_DIR}/${PN}/*"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.