[英]How to invoke a python module in Yocto bitbake recipe?
I am working on a linux open-embedded project (Yocto), and I need to use gRPC.我正在开发一个 linux 开放嵌入式项目(Yocto),我需要使用 gRPC。
Below are my recipes that try to invoke the gRPC python module.下面是我尝试调用 gRPC python 模块的食谱。 (grpcio-tools)
(grpcio 工具)
In local.conf在 local.conf 中
TOOLCHAIN_HOST_TASK_append = " nativesdk-python3-grpcio-tools"
TOOLCHAIN_TARGET_TASK_append = " python3-grpcio-tools"
Then is my.bb file, I try to add it as Depends.然后是 my.bb 文件,我尝试将其添加为 Depends。
DEPENDS += " python3-grpcio-tools"
do_compile(){
python3 -m grpc_tools.protoc -I ${S} --python_out=. --grpc_python_out=. ${S}/tests/rcu_ser.proto
}
But it fails to find the python module during bitbake.但它在 bitbake 期间找不到 python 模块。 Below is the failure code:
下面是失败代码:
Please teach me how to invoke the python module during bitbake.请教我如何在 bitbake 期间调用 python 模块。 Thank you very much.
非常感谢。
If you want to use dependency on the host during compile time you must always depend to native version of a recipe.如果您想在编译期间使用对主机的依赖,则必须始终依赖于本机版本的配方。 Modify your recipe as following:
修改你的食谱如下:
inherit python3native
DEPENDS += "python3-grpcio-tools-native"
RDEPENDS_${PN} += "python3 python3-grpcio-tools"
This thread helped me so I thought I would share a complete.bb recipe that's working for cross-compiling a proto file into the necessary files for a Petalinux / Yocto Zeus gRPC server using python.这个线程帮助了我,所以我想我会分享一个完整的.bb 配方,该配方用于使用 python 将 proto 文件交叉编译为 Petalinux / Yocto Zeus gRPC 服务器所需的文件。 I'm no bitbake expert.
我不是位烘焙专家。 This installs the resulting pb2 files in /usr/bin and compiles them using python3-grpcio-tools for the target device (which may be an older/different version than what you have on your build machine).
这会将生成的 pb2 文件安装在 /usr/bin 中,并使用 python3-grpcio-tools 为目标设备编译它们(这可能是比您构建机器上的版本更旧/不同的版本)。 The proto file includes protobuf definitions as well as rpc definitions, hence the generated _pb2_grpc.py file.
proto 文件包括 protobuf 定义以及 rpc 定义,因此生成了 _pb2_grpc.py 文件。
SUMMARY = "My summary."
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI = " \
file://my_proto.proto \
"
inherit python3native
RDEPENDS_${PN} = " \
python3-core \
python3-protobuf \
python3-grpcio \
"
DEPENDS += " \
python3-grpcio-tools-native \
"
do_compile() {
python3 -m grpc.tools.protoc -I${WORKDIR} --python_out=${WORKDIR}/. --grpc_python_out=${WORKDIR}/. ${WORKDIR}/my_proto.proto
}
do_install() {
install -Dm 0755 ${WORKDIR}/my_proto_pb2.py ${D}/${bindir}/my_proto_pb2.py
install -Dm 0755 ${WORKDIR}/my_proto_pb2_grpc.py ${D}/${bindir}/my_proto_pb2_grpc.py
}
FILES_${PN} = " \
${bindir}/my_proto_pb2.py \
${bindir}/my_proto_pb2_grpc.py \
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.