为不可用的 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
上述步骤在您的$BUILD_DIR 中创建了一个文件夹workspace,并为存储库创建了自动生成的食谱。
-
编辑食谱
devtool edit-recipe influxdb-python
-
相应地将DEPEND_${PN} 和RDEPENDS_${PN} 添加或检查到您的食谱中。我将influxdb-python 的所有requirements.txt 添加到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",因此目标上的所有主要内容都可用。
配方结构
GitHub Gist for Recipes
我遵循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 和 bitbake -k pynmea2
或与
devtool build influxdb-python 和 devtool build pynmea2
如果您没有错误,则可以使用以下命令将其部署到目标上:
devtool deploy-target influxdb-python user@machineIP:dest_folder
检查
您可以通过触发 python shell 来检查
# python3
>> import influxdb-python
>> import pyserial
如果导入没有抛出缺少模块的错误,那么它是成功的!!
最后的步骤
注意:如果您使用krogoth 或更低版本,您将不得不手动将您的食谱移动到您的元层
- 现在将这些食谱包含在您的
conf/local.conf 和IMAGE_INSTALL_append = " influxdb-python pynmea2" 和bitbake -k your-image-name
自定义应用程序
尚未测试。
但我想我会像YoctoCookBook Repository for hello-world 中提到的那样简单地将我的应用程序添加到我的meta 层。
掘金
-
${PYTHON_PN}-modules 真是救世主。我尝试手动添加运行时依赖,每次我在板上部署它时总是缺少一些依赖项。但是添加modules 解决了一个实例中所有缺少的deps 问题。
-
我不确定何时使用 DEPENDS_${PN},但我认为大多数 python 应用程序都依赖于基本的 python-modules,因此我添加了它们。
-
不是 YOCTO 专家,但这只是我在过去 2 周内的发现。 Yocto 中缺少 Python 的适当示例。希望这对某人有所帮助。