简体   繁体   English

如何在 Yocto bitbake 配方中调用 python 模块?

[英]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.

相关问题 如何为gRPC ++编写yocto食谱? - How to write a yocto recipe for gRPC++? 构建依赖于 grpc 的 Yocto bitbake 配方,grpc-native 失败说 grpc_cpp_plugin 不存在 - Building a Yocto bitbake recipe, which depends on grpc, grpc-native fails saying the the grpc_cpp_plugin does not exist 如何在蝗虫中调用 GRPC python 客户端? - How to invoke a GRPC python client in locust? 如何在yocto上移植grpc helloworld(CPP)示例 - How to port grpc helloworld(CPP) example on yocto 如何在自己的Yocto软件包中访问protoc编译器并参考gRPC库 - How to access protoc compiler in own Yocto package and reference to gRPC libs 尝试在Splunk上安装gRPC python模块 - Trying to install gRPC python module on Splunk python生成的grpc脚本没有模块错误 - no module error for python generated grpc script 将Python的grpcio模块嵌入到Bazel项目中 - Embed Python's grpcio module into a Bazel project bitbake grpc交叉编译/配置失败,并出现错误c-ares :: cares引用文件/usr/lib/libcares.so.2.2.0 - bitbake grpc cross compile/configure failing with error c-ares::cares references the file /usr/lib/libcares.so.2.2.0 使用cx_Freeze使grpc python代码成为exe文件:没有名为“ pkg_resources”的模块 - make grpc python code to exe with cx_Freeze : No module named 'pkg_resources'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM