如何通过Yocto安装编译好的TensorRT Python Wheel包?
Yocto安装TensorRT Python .whl包失败问题
我为特定版本Python编译了无额外依赖的TensorRT Python绑定,现在要将生成的.whl文件安装到Yocto镜像中,使用了如下配方:
SUMMARY = "NVIDIA® TensorRT™, an SDK for high-performance deep learning inference, includes a deep learning inference optimizer and runtime that delivers low latency and high throughput for inference applications." HOMEPAGE = "https://github.com/NVIDIA/TensorRT" SRC_URI = "file://tensorrt-8.2.1.9-cp38-none-linux_aarch64.whl" LICENSE = "Proprietary" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Proprietary;md5=0557f9d92cf58f2ccdd50f62f8ac0b28" DEPENDS += "python3 python3-pip" FILES_${PN} += "\ ${libdir}/${PYTHON_DIR}/site-packages/* \ " do_install() { pip install ${S}/tensorrt-8.2.1.9-cp38-none-linux_aarch64.whl }
但配方在do_install步骤执行失败,错误信息:
ERROR: Execution of '/home/user/Desktop/tegra-demo-distro/build/tmp/work/aarch64-oe4t-linux/tensorrt/8.2.1-r0/temp/run.do_install.56472' failed with exit code 127
问题原因
Exit code 127表示找不到指定命令,这里是因为Yocto的构建环境是隔离的,直接调用pip无法定位到正确的工具;同时默认的pip install会把包安装到构建主机环境,而非Yocto的目标根文件系统。
修正后的配方
SUMMARY = "NVIDIA® TensorRT™, an SDK for high-performance deep learning inference, includes a deep learning inference optimizer and runtime that delivers low latency and high throughput for inference applications." HOMEPAGE = "https://github.com/NVIDIA/TensorRT" SRC_URI = "file://tensorrt-8.2.1.9-cp38-none-linux_aarch64.whl" LICENSE = "Proprietary" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Proprietary;md5=0557f9d92cf58f2ccdd50f62f8ac0b28" DEPENDS += "python3 python3-pip" # 声明运行时依赖,确保镜像包含Python核心环境 RDEPENDS_${PN} += "python3-core" FILES_${PN} += "\ ${libdir}/${PYTHON_DIR}/site-packages/* \ " do_install() { # 使用Yocto提供的pip变量,指定安装到目标根目录,禁用依赖检查 ${PYTHON_PIP} install --root=${D} --no-deps ${S}/tensorrt-8.2.1.9-cp38-none-linux_aarch64.whl }
关键修改点
- 用Yocto官方提供的
${PYTHON_PIP}变量替代直接调用pip,确保在构建隔离环境中能找到正确的工具 - 添加
--root=${D}参数,强制将包安装到Yocto的目标根文件系统(${D}是Yocto内置的安装目录变量) - 添加
--no-deps参数,避免pip尝试自动下载依赖(适配你的whl无额外依赖的特性) - 添加
RDEPENDS_${PN}声明运行时依赖,确保最终镜像包含Python核心运行环境
内容的提问来源于stack exchange,提问作者Damien
相关产品推荐
相关产品推荐

