python-3.x - 在 yocto 中为 python 应用程序编写一个配方
问题描述
我有一个简单的 python 应用程序,它可以:
- 从 GPS 获取信息
- 解析信息
- 将其存储在 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
我已经找到Python3pyserial
的包中。这意味着在董事会上我可能需要做。pip3 install pynmea2 influxdb
考虑到所有上述 pip 依赖项,您如何继续编写我的应用程序的配方?
我没有找到任何为 python 应用程序编写食谱的教程。(相反,应用程序在yoctoNode
的 wiki 页面上确实有一些指导。
在检查meta-python
层中的一些食谱后,我发现了一些.inc
文件,但不知道如何去做
解决方案
为不可用的 python 应用程序创建食谱
由于influxdb-python
并且pynmea2
不能作为标准 python 食谱使用,我首先使用devtool
.
脚步
用于
devtool
添加influxdb-python
devtool add influxdb-python https://github.com/influxdata/influxdb-python/archive/v5.2.0.tar.gz
用于
devtool
添加pynmea2
devtool add pynmea2 https://github.com/Knio/pynmea2/archive/1.7.1.tar.gz
上述步骤workspace
在您的文件夹中创建了一个文件夹,$BUILD_DIR
并为存储库创建了自动生成的食谱。
编辑食谱
devtool edit-recipe influxdb-python
相应地添加或检查您
DEPEND_${PN}
的RDEPENDS_${PN}
食谱。我将所有的requirements.txt
for添加influxdb-python
到RDEPENDS_${PN}
即。RDEPEND_${PN} += "${PYTHON_PN}-modules ${PYTHON_PN}-requests ${PYTHON_PN}-dateutil ${PYTHON_PN}-pytz ${PYTHON_PN}-six"
注意:我没有添加
pandas
或者numpy
因为它们与我的应用程序无关。我
DEPENDS_${PN} = "${PYTHON_PN}-modules
也加了。
注意:执行相同的操作,
pynmea2
但由于requirements.txt
我没有添加任何RDEPENDS_${PN} = "${PYTHON_PN}-modules"
内容,因此目标上的所有主要内容都可用。
配方结构
我遵循meta-python
文件夹的结构,其中每个食谱包括:
recipe.inc
recipe_version_number.bb
influxdb_python.inc
保留所有从devtool
即生成的东西。
# 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
。对于 python2.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
您可以使用andbitbake -k pynmea2
或使用
devtool build influxdb-python
and测试它们
devtool build pynmea2
如果您没有错误,则可以使用以下命令将其部署在目标上:
devtool deploy-target influxdb-python user@machineIP:dest_folder
检查
您可以通过触发 python shell 来检查
# python3
>> import influxdb-python
>> import pyserial
如果导入没有抛出缺少模块的错误,那么它是成功的!!
最后的步骤
您可以取消部署模块:
devtool undeploy-target recipe_name [address of target]
将食谱发送给您自定义元层
devtool finish recipe_name ../meta-custom
注意:如果您正在使用
krogoth
或降低,您将不得不手动将您的食谱移动到您的元层
- 现在将这些食谱包含在您的
conf/local.conf
withIMAGE_INSTALL_append = " influxdb-python pynmea2"
和bitbake -k your-image-name
自定义应用程序
尚未测试。
但我想我会像YoctoCookBook Repository 中hello-world
提到的那样简单地将我的应用程序添加到我的meta
层中。
掘金
${PYTHON_PN}-modules
真的是救世主。我尝试手动添加运行时依赖,每次我在板上部署它时总是缺少一些依赖项。但是modules
在一个实例中添加解决了所有缺失的 deps 问题。我不确定何时使用
DEPENDS_${PN}
,但我认为大多数 python 应用程序都依赖于基础,python-modules
因此我添加了它们。不是 YOCTO 专家,但这只是我过去两周的发现。Yocto 中缺少 Python 的适当示例。希望这可以帮助某人。
推荐阅读
- java - JLabel 上的图像
- android - 如何在地图片段活动上显示按钮
- python - 将车辆定位在赛道上的行驶方向
- javascript - 如何在 socket.io 中获取活动房间列表
- c - MSVC const 正确性:虚假 C4090 警告
- scala - reduceLeft 如何处理返回 Future 的函数序列
- node.js - React/Node:我应该在哪里存储不使用外部 API 的类似琐事的应用程序的问题/答案?
- java - 如何对具有返回列表的地图的流进行平面映射?
- android - 如何在recyclerview中控制Exoplayer
- javascript - 开玩笑正则表达式和浏览器控制台测试中的差异