本文介绍了在yocto中为python应用程序编写食谱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的python应用程序,它可以:

I have a simple python application which does:


  1. 从GPS获取信息

  2. 解析信息

  3. 将其存储在InfluxDB中

打包要求:

certifi==2018.4.16
chardet==3.0.4
idna==2.6
influxdb==5.0.0
pynmea2==1.12.0
pyserial==3.4
python-dateutil==2.7.3
pytz==2018.4
requests==2.18.4
six==1.11.0
urllib3==1.22

以上是通过使用以下命令生成:

The above is generated by using:

pip3 install pynmea2 pyserial influxdb

在 OpenEmbedded Layers Index 中,我已经找到了 Python3 的 pyserial 软件包。这意味着在板上,我可能只需要做 pip3安装pynmea2 influxdb 。

In the OpenEmbedded Layers Index I have already found pyserial package for Python3. Which implies on the board I just might need to do pip3 install pynmea2 influxdb.

你如何继续写作

我的应用程序配方中是否考虑了上述所有pip依赖项?我没有找到任何有关为python应用程序编写配方的教程。 (相反, Node 应用程序确实对。

There aren't any tutorials I have found for writing recipes for python applications. (On the contrary Node applications do have some guidance on the wiki page for yocto.

在检查我发现的 meta-python 层中的一些食谱后某些 .inc 文件,但不确定如何处理

Upon checking some recipes in meta-python layer I found some .inc files but not sure how to go about it

推荐答案

为不可用的python应用程序创建食谱


由于 influxdb-python 和 pynmea2 不能作为标准python配方使用,我首先使用 devtool 为它们创建配方。

Creating Recipes for non-available python apps

Since influxdb-python and pynmea2 are not available as standard python recipes, I began by creating recipes for them using devtool.


  1. 使用 devtool 添加 influxdb-python

devtool添加influxdb-python https://github.com/influxdata/influxdb-python/archive/v5.2.0.tar.gz

使用 devtool 添加 pynmea2

devtool添加pynmea2 https://github.com/Knio/pynmea2/archi ve / 1.7.1.tar.gz

上述步骤创建了一个文件夹工作区在您的 $ BUILD_DIR 中,并为存储库创建了自动生成的配方。

The above mentioned steps creates a folder workspace in your $BUILD_DIR and created auto-generated recipes for the repos.

编辑配方

devtool编辑配方influxdb-python

添加或检查 DEPEND _ $ {PN} 和 RDEPENDS _ $ {PN} 相应地添加到您的食谱中。我将 influxdb-python 的所有 requirements.txt 添加到 RDEPENDS _ $ {PN} 即。

add or check DEPEND_${PN} and RDEPENDS_${PN} to your recipes accordingly. I added all the requirements.txt for influxdb-python to RDEPENDS_${PN} viz.

RDEPEND _ $ {PN} + = $ {PYTHON_PN}-模块$ {PYTHON_PN}-请求$ {PYTHON_PN} -dateutil $ {PYTHON_PN} -pytz $ {PYTHON_PN}-六个

注意:我尚未添加 pandas 或 numpy ,因为它们与我的应用程序无关。

NOTE: I have not added pandas or numpy as they aren't relevant for my application.

我添加了 DEPENDS _ $ {PN} =" $ {PYTHON_PN}-模块也是。



食谱结构


我遵循 meta-python 文件夹的结构,其中每个食谱包括:

I followed the meta-python folder's structure where each of the recipes consists of :


  • recipe.inc

  • recipe_version_number.bb

  • recipe.inc
  • recipe_version_number.bb

在 influxdb_python.inc 保留从 devtool viz生成的所有东西。

In the influxdb_python.inc keep all the stuff generated from devtool viz.

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
#
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=046523829184aac3703a4c60c0ae2104"

HOMEPAGE = "https://github.com/influxdb/influxdb-python"
SUMMARY = "InfluxDB client"

SRC_URI = "https://github.com/influxdata/influxdb-python/archive/v${PV}.tar.gz"
SRC_URI[md5sum] = "105d88695151e241523b31dd1375096e"
SRC_URI[sha256sum] = "620de85bcca5207b06ec1565884b6d10b4be01d579a78e08b1e922f453fdac05"

DEPENDS_${PN} = "${PYTHON_PN}-modules"
RDEPENDS_${PN} = "${PYTHON_PN}-modules ${PYTHON_PN}-requests ${PYTHON_PN}-dateutil ${PYTHON_PN}-pytz ${PYTHON_PN}-six"

在 influxdb_python_5.2.0.bb 中,添加了以下几行:

In the influxdb_python_5.2.0.bb I added the following lines:

inherit setuptools3 pypi
require influxdb-python.inc


类似地,我对<$ c $做同样的事情c> pynmea2.inc :

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
#
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=bb5e173bc54080cb25079199959ba6b6"

HOMEPAGE = "https://github.com/Knio/pynmea2"
SUMMARY = "Python library for the NMEA 0183 protcol"

SRC_URI = "https://github.com/Knio/pynmea2/archive/${PV}.tar.gz"
SRC_URI[md5sum] = "a90baf61f4e676bef76099e4bd7c0581"
SRC_URI[sha256sum] = "8f8f68623bd2d5dab7f04a9c31813a3f4aa15467db0373cbce6b9b0ae44ca48e"

#DEPENDS_${PN} = "${PYTHON_PN}-datetime ${PYTHON_PN}-threading ${PYTHON_PN}-io"
DEPENDS_${PN} = "${PYTHON_PN}-modules"
# WARNING: the following rdepends are determined through basic analysis of the
# python sources, and might not be 100% accurate.
RDEPENDS_${PN} = "${PYTHON_PN}-modules"

对于 pynmea2_1.7.1.bb :

inherit setuptools3 pypi
require pynmea2.inc


烘焙食谱


您可以使用
bitbake -k influxdb-python 和进行测试bitbake -k pynmea2
或使用
devtool build influxdb-python 和 devtool build pynmea2

如果没有错误,则可以使用以下命令将其部署在目标上:

If you have no errors then you can deploy it on target using:

devtool deploy-target influxdb-python user@machineIP:dest_folder


检查


您可以通过触发python shell进行检查

Checks

You can check by firing the python shell

# python3

 >> import influxdb-python
 >> import pyserial

如果导入没有抛出丢失的模块错误,那就成功了!

if the import is throws no missing modules error then it is success!!


  • 您可以取消部署模块: devtool undeploy-target recipe_name [目标地址]

将配方发送到您的自定义元层 devtool finish recipe_name ../meta-custom

send the recipes to you custom meta layer devtool finish recipe_name ../meta-custom



  • 现在将这些食谱包含在 conf / local.conf 中,并带有 IMAGE_INSTALL_append =" influxdb-python pynmea2 和 bitbake -k your-image-name

    • Now include these recipes in your conf/local.conf with IMAGE_INSTALL_append = " influxdb-python pynmea2" and bitbake -k your-image-name
    • 但是我想我会简单地添加我的应用就像和我的 meta 层。

      But I think I will simple add my app like mentioned in YoctoCookBook Repository for hello-world with my meta layer.


      • $ {PYTHON_PN} -modules 确实是一个救星。我尝试手动添加运行时部门,每次将其部署在板上时,总是会丢失一些依赖项。但是添加 modules 解决了实例中所有缺失的deps问题。

      • ${PYTHON_PN}-modules is a saviour really. I tried manually added runtime deps and everytime i deployed it on the board there were always some dependencies missing. But adding the modules solved all the missing deps issue in an instance.

      I我不确定何时使用 DEPENDS _ $ {PN} ,但是我认为大多数python应用程序都依赖于基本的 python-modules 因此,我将它们添加了。

      I am not sure when to use DEPENDS_${PN} but I assume most python applications depend on the basic python-modules hence I added them.

      不是专业专家,但这只是我最近两周的发现。 Yocto中缺少适当的Python示例。希望这对某人有帮助。

      NOT A YOCTO EXPERT but this is just my finding in the last 2 weeks. There is a lack of proper examples for Python in Yocto. hope this helps someone.

      这篇关于在yocto中为python应用程序编写食谱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:33