[Python] How to install dependencies from requirements.txt in a Yocto recipe for a local...

Discussão em 'Python' iniciado por Stack, Julho 17, 2025.

  1. Stack

    Stack Membro Participativo

    What I should have:


    I want my Yocto Project to build a package for my Python project with all dependencies inside. The project has to run out of box on the resulting read-only sdcard image.
    It simply should install all requirements in the required version to the package.

    What I tried without luck:

    Calling pip in do_install():


    "pip/pip3 is not found", even it's in RDEPENDS. Anyway, I really prefer this way.

    With inherit pypi:


    When trying with inherit pypi, it tries to get also my local sources (my pyton project) from pypi. And I have always to copy the requirements to the recipe. This is not my preferred way.

    Calling pip in pkg_postinst():


    It tries to install the modules on first start and fails, because the system has no internet connection and it's a read-only system. It must run out of the box without installation on first boot time. Does its stuff to late.

    Where I'll get around:


    There should be no need to change anything in the recipes when something changes in requirements.txt.

    Background information


    I'm working with Yocto Rocko in a Linux environment.
    In the Hostsystem, there is no pip installed. I want to run this one installed from RDEPENDS in the target system.

    Building the Package (only this recipe) with:

    bitbake myproject


    Building the whole sdcard image:

    bitbake myProject-image-base

    The recipe:


    myproject.bb (relevant lines):

    RDEPENDS_${PN} = "python3 python3-pip"

    APP_SOURCES_DIR := "${@os.path.abspath(os.path.dirname(d.getVar('FILE', True)) + '/../../../../app-sources')}"

    FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

    SRC_URI = " \
    file://${APP_SOURCES_DIR}/myProject \
    ...
    "

    inherit allarch # tried also with pypi and setuptools3 for the pypi way.

    do_install() { # Line 116
    install -d -m 0755 ${D}/myProject
    cp -R --no-dereference --preserve=mode,links -v ${APP_SOURCES_DIR}/myProject/* ${D}/myProject/
    pip3 install -r ${APP_SOURCES_DIR}/myProject/requirements.txt
    # Tried also python ${APP_SOURCES_DIR}/myProject/setup.py install
    }

    # Tried also this, but it's no option because the data MUST be included in the Package:
    # pkg_postinst_${PN}() {
    # #!/bin/sh -e
    # pip3 install -r /myProject/requirements.txt
    # }

    FILES_${PN} = "/myProject/*"

    Resulting Errors:


    Expected to install the listed modules from requirements.txt into the myProject package, so that the python app will run directly on the resulting readonly sdcard image.

    With pip, I get:

    | /*/tmp/work/*/myProject/0.1.0-r0/temp/run.do_install: 116: pip3: not found
    | WARNING: exit code 127 from a shell command.
    | ERROR: Function failed: do_install ...


    When using pypi:

    404 Not Found
    ERROR: myProject-0.1.0-r0 do_fetch: Fetcher failure for URL: 'https://files.pythonhosted.org/packages/source/m/myproject/myproject-0.1.0.tar.gz'. Unable to fetch URL from any source.


    => But it should not fetch myProject, since it is already local and nowhere remote.

    Any ideas? What would be the best way to reach to a ready to use sdcard image without the need to change recipes when requirements.txt changes?

    Continue reading...

Compartilhe esta Página