代码之家  ›  专栏  ›  技术社区  ›  Shan-Desai askovpen

用yocto为python应用程序编写一个配方

  •  5
  • Shan-Desai askovpen  · 技术社区  · 7 年前

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

    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          
    

    以上是通过以下方式生成的:

    pip3 install pynmea2 pyserial influxdb

    OpenEmbedded Layers Index 我已经找到了 pyserial 包装 蟒蛇3 . 这意味着在董事会上我可能只需要做 pip3 install pynmea2 influxdb .

    您如何在编写我的应用程序的配方时考虑到上面提到的所有PIP依赖性?

    我没有找到任何关于编写Python应用程序配方的教程。(相反 Node 应用程序确实对 wiki page for yocto .

    在检查一些食谱时 meta-python 我发现了一些 .inc 文件,但不确定如何处理

    1 回复  |  直到 7 年前
        1
  •  7
  •   Shan-Desai askovpen    6 年前

    为不可用的python应用程序创建配方

    自从 influxdb-python pynmea2 不能作为标准的python食谱使用,我首先使用 devtool .

    步骤

    1. 使用 开发工具 添加 流入xdb python

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

    2. 使用 开发工具 添加 品名A2

      devtool add pynmea2 https://github.com/Knio/pynmea2/archive/1.7.1.tar.gz

    上述步骤创建文件夹 workspace 在你的 $BUILD_DIR 并为回购协议创建自动生成的配方。

    1. 编辑食谱

      devtool edit-recipe influxdb-python

    2. 添加或检查 DEPEND_${PN} RDEPENDS_${PN} 根据你的食谱。我把所有的 requirements.txt 对于 流入xdb python 订单号PN

      RDEPEND_${PN} += "${PYTHON_PN}-modules ${PYTHON_PN}-requests ${PYTHON_PN}-dateutil ${PYTHON_PN}-pytz ${PYTHON_PN}-six"

      注释 :我没有添加 pandas numpy 因为它们与我的申请无关。

    3. 我添加了 DEPENDS_${PN} = "${PYTHON_PN}-modules 也。

    注释 :对 品名A2 但是因为它没有 要求.txt 我添加了 RDEPENDS_${PN} = "${PYTHON_PN}-modules" 所以所有主要的事情都可以在目标上实现。

    配方结构

    GitHub Gist for Recipes

    我跟着 meta-python 文件夹的结构,其中每个配方包括:

    • recipe.inc
    • recipe_version_number.bb

    influxdb_python.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=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 我添加了以下行:

    inherit setuptools3 pypi                              
    require influxdb-python.inc
    

    注释 :我添加了 setuptools3 因为我想在上面运行我的应用程序 python3.5 . 用于2.7号蟒蛇 setuptools .

    同样,我也为 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

    如果没有错误,则可以使用以下方法在目标上部署它:

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

    检查

    你可以通过发射巨蟒壳来检查

    # python3 
    
     >> import influxdb-python
     >> import pyserial
    

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

    最后步骤

    • 您可以取消部署模块: devtool undeploy-target recipe_name [address of target]

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

    注释 :如果使用 krogoth 或者降低你将不得不手动移动你的食谱到你的元层。

    • 现在把这些食谱包括在你的 conf/local.conf 具有 IMAGE_INSTALL_append = " influxdb-python pynmea2" bitbake -k your-image-name

    自定义应用程序

    尚未测试。

    但我想我会简单地添加我的应用程序,如中所述 YoctoCookBook Repository for hello-world 与我的 meta 层。

    金块

    • ${PYTHON_PN}-modules 真的是救世主。我尝试手动添加运行时deps,每次我在板上部署它时,总会缺少一些依赖项。但添加 modules 解决了实例中所有缺失的DEPS问题。

    • 我不确定什么时候用 DEPENDS_${PN} 但我认为大多数Python应用程序都依赖于 python-modules 所以我加了它们。

    • 不是Yocto专家 但这只是我最近两周的发现。在yocto中没有合适的Python示例。希望这能帮助别人。