首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >用yocto编写python应用程序的配方

用yocto编写python应用程序的配方
EN

Stack Overflow用户
提问于 2018-05-20 07:27:51
回答 1查看 6.8K关注 0票数 7

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

  1. 从全球定位系统获取信息
  2. 解析信息
  3. 将其存储在InfluxDB中

一揽子要求:

代码语言:javascript
运行
AI代码解释
复制
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中,我已经找到了Python3pyserial包。这意味着我可能需要做pip3 install pynmea2 influxdb

如何在编写我的应用程序的配方时考虑到上面提到的pip依赖关系?

对于编写python应用程序的配方,我没有找到任何教程。(相反,Node应用程序确实对yocto wiki页面有一些指导。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-04 01:16:58

为不可用的python应用程序创建累赘

由于influxdb-pythonpynmea2不能作为标准python菜谱使用,所以我首先使用devtool为它们创建了菜谱。

步骤

  1. 使用devtool添加influxdb-python devtool add influxdb-python https://github.com/influxdata/influxdb-python/archive/v5.2.0.tar.gz
  2. 使用devtool添加pynmea2 devtool add pynmea2 https://github.com/Knio/pynmea2/archive/1.7.1.tar.gz

上面提到的步骤在您的workspace中创建一个文件夹$BUILD_DIR,并为repos创建自动生成的菜谱。

  1. 编辑菜谱 devtool edit-recipe influxdb-python
  2. 相应地向菜谱中添加或检查DEPEND_${PN}RDEPENDS_${PN}。我将所有requirements.txt for influxdb-python添加到RDEPENDS_${PN} viz中。 RDEPEND_${PN} += "${PYTHON_PN}-modules ${PYTHON_PN}-requests ${PYTHON_PN}-dateutil ${PYTHON_PN}-pytz ${PYTHON_PN}-six" 注意::我没有添加pandasnumpy,因为它们与我的应用程序无关。
  3. 我还添加了DEPENDS_${PN} = "${PYTHON_PN}-modules

注意到:对pynmea2执行同样的操作,但是由于它没有任何requirements.txt,所以我添加了RDEPENDS_${PN} = "${PYTHON_PN}-modules",所以目标上可以使用所有重要的东西。

配方结构

GitHub要旨

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

  • recipe.inc
  • recipe_version_number.bb

influxdb_python.inc中保留devtool生成的所有内容。

代码语言:javascript
运行
AI代码解释
复制
# 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中,我添加了以下几行:

代码语言:javascript
运行
AI代码解释
复制
inherit setuptools3 pypi                              
require influxdb-python.inc

注意到:我添加了setuptools3,因为我希望在python3.5上运行我的应用程序。对于python2.7,使用setuptools

类似地,我对pynmea2.inc也做了同样的事情

代码语言:javascript
运行
AI代码解释
复制
# 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

代码语言:javascript
运行
AI代码解释
复制
inherit setuptools3 pypi
require pynmea2.inc

烘烤菜谱

您可以用bitbake -k influxdb-pythonbitbake -k pynmea2或者devtool build influxdb-pythondevtool build pynmea2来测试它们。

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

代码语言:javascript
运行
AI代码解释
复制
devtool deploy-target influxdb-python user@machineIP:dest_folder

检查

您可以通过触发python外壳来进行检查。

代码语言:javascript
运行
AI代码解释
复制
# python3 

 >> import influxdb-python
 >> import pyserial

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

最后步骤

  • 您可以取消部署模块:devtool undeploy-target recipe_name [address of target]
  • 将菜谱发送给您自定义的元层devtool finish recipe_name ../meta-custom

注意:如果您正在使用krogoth或更低的值,则必须手动将菜谱移动到元层。

  • 现在将这些菜谱与IMAGE_INSTALL_append = " influxdb-python pynmea2"bitbake -k your-image-name一起包含在您的IMAGE_INSTALL_append = " influxdb-python pynmea2"bitbake -k your-image-name

自定义应用

还没测试过。

但我想我会简单地添加我的应用程序,就像在hello-world中提到的那样,我的meta层。

鸡块

  • ${PYTHON_PN}-modules是真正的救世主。我尝试手动添加运行时dep,每次我在板上部署它时,总是缺少一些依赖项。但是添加modules解决了一个实例中所有缺失的deps问题。
  • 我不确定何时使用DEPENDS_${PN},但我假设大多数python应用程序依赖于基本的python-modules,因此我添加了它们。
  • 不是YOCTO的专家,但这只是我在过去2周里的发现。在Yocto中,Python缺乏适当的示例。希望这能帮上忙。
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50436413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档