Open-AI with python

Dear community,
We want to include in our image the openai package for python and we can’t find any way. We are using YOCTO and your BSP 6.3.
We have installed the package using PIP and everything works correctly, but this is not an option because our system is read-only.
Any ideas?
Best regards,
Julián

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Julián,

To include the OpenAI package for Python in your Yocto Project build for a read-only system, you’ll need to create a custom recipe that fetches and installs the package into your image during the build process. Since you are using BSP 6.3, here’s a general approach to achieve this:

  1. Create a Custom Layer: If you haven’t already, create a custom layer in your Yocto Project setup to hold your custom recipes. This keeps your customizations separate from the default layers provided by Toradex.

  2. Write a Bitbake Recipe for OpenAI: You need to create a new recipe for the OpenAI Python package. This recipe will specify how to fetch, compile (if necessary), and install the package into your image. Here’s an example of what the recipe (python-openai_1.0.bb) might look like:

SUMMARY = "OpenAI Python package"
SECTION = "devel/python"
LICENSE = "CLOSED"

inherit pypi setuptools

PYPI_PACKAGE = "openai"

RDEPENDS_${PN} += " \
    python3-core \
    python3-setuptools \
    python3-pip \
    "

do_install_append() {
    # Ensure the package is installed into the image's site-packages directory
    oe_runpip install --root ${D} ${S}
}

This is a simplified example. Depending on the OpenAI package dependencies, you might need to add more to the RDEPENDS_${PN} variable or adjust the installation command.

  1. Add the Package to Your Image: Once the recipe is created, you need to add the package to your image. Modify your image recipe or the local.conf file to include the OpenAI package:
IMAGE_INSTALL_append = " python-openai"
  1. Build Your Image: With the recipe in place and the package added to your image configuration, you can now build your Yocto Project image. The build process should fetch the OpenAI package, build it (if necessary), and include it in your read-only system image.

  2. Testing: After the build completes, deploy the image to your target device and verify that the OpenAI package is correctly installed and functional.

This approach allows you to include Python packages directly in your Yocto Project builds, making them part of the read-only system image and eliminating the need for runtime installation via PIP.

Best regards,
Torad

Please, also check if these links can help you solve your problem:

Python in Linux | Toradex Developer Center.

Hi @ToradexAI,
Thank you very much for your answer :wink:, I tried what you said and it gives an error with the setuptools package :pleading_face:.

Could not inherit file classes/setuptools.bbclass

Hello @jbruno,

The answer from the @ToradexAI is likely not too far from what is actually needed to add a python-openai recipe to your Yocto build.

I am looking into this topic, but here are some preliminary findings:

  • The suggested do_install_append is incorrect and not needed.
  • Instead of inheriting the setuptools class, python_setuptools_build_meta should be used.
  • Some runtime dependencies still need to be resolved, such as python3-pandas.

When I have further updates I will send them here.

Best Regards,
Bruno