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?
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:
-
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.
-
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.
- 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"
-
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.
-
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:
Hi @ToradexAI,
Thank you very much for your answer , I tried what you said and it gives an error with the setuptools package .
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
Hello @jbruno,
I did some more research and tests and installing this package with Yocto will not be a very easy task but should be possible.
You will need to make sure that the build system used by the openai-python
package is available in Yocto.
Looking at the project’s pyproject.toml, you can see that the used build system is hatchling
:
...
[build-system]
requires = ["hatchling", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"
...
Unfortunately the support for this build system is not available by default.
It could be added, but would require some work.
The following are some useful examples which could be helpful in this process:
- python3-installer recipe: this recipe also uses a different build system,
python_flit_core
. - python_flit_core class: this is one of the classes inherited by the
python3-installer
recipe.
Best Regards,
Bruno
HI @bruno.tx,
Our version of YOCTO does not support those packages. We are trying to install one by one the openai-python requirements and we have copied the openai-python repository to a compressed file. When we have something clear we will share it in this post.
Thank you very much for the information.
Best regards,
Julián