在 yocto 中为 python 应用程序编写食谱
Write a recipe in yocto for a python application
我有一个简单的 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
中,我已经找到 pyserial
包用于 Python3。这意味着在董事会上我可能只需要做 pip3 install pynmea2 influxdb
.
在考虑上述所有 pip 依赖项的情况下,您如何继续编写我的应用程序的配方?
我找不到任何为 python 应用程序编写方法的教程。 (相反 Node
应用程序在 wiki page for yocto 上确实有一些指导。
检查 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
上述步骤在您的 $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
NOTE: Perform the same for pynmea2
but since it does not have any requirements.txt
I added RDEPENDS_${PN} = "${PYTHON_PN}-modules"
so all major things are available on the target.
配方结构
我遵循 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
NOTE: I added setuptools3
since I want my app to be run on python3.5
. For python2.7 use 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
如果导入抛出没有丢失的模块错误则成功!!
最后的步骤
您可以取消部署模块:devtool undeploy-target recipe_name [address of target]
将食谱发送给您自定义元层devtool finish recipe_name ../meta-custom
NOTE: If you are using krogoth
or lower the you will have to move your recipes to you meta layer manually
- 现在将这些食谱包含在您的
conf/local.conf
中 IMAGE_INSTALL_append = " influxdb-python pynmea2"
和 bitbake -k your-image-name
自定义应用程序
Not tested yet.
但我想我会像 YoctoCookBook Repository for hello-world
中提到的那样简单地将我的应用程序添加到我的 meta
层。
金块
${PYTHON_PN}-modules
真是救星。我尝试手动添加运行时依赖项,每次我将它部署到板上时,总会缺少一些依赖项。但是添加 modules
解决了实例中所有缺失的 deps 问题。
我不确定何时使用 DEPENDS_${PN}
但我认为大多数 python 应用程序都依赖于基本 python-modules
因此我添加了它们。
不是 YOCTO 专家 但这只是我最近两周的发现。 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
中,我已经找到 pyserial
包用于 Python3。这意味着在董事会上我可能只需要做 pip3 install pynmea2 influxdb
.
在考虑上述所有 pip 依赖项的情况下,您如何继续编写我的应用程序的配方?
我找不到任何为 python 应用程序编写方法的教程。 (相反 Node
应用程序在 wiki page for yocto 上确实有一些指导。
检查 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
上述步骤在您的 $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
NOTE: Perform the same for
pynmea2
but since it does not have anyrequirements.txt
I addedRDEPENDS_${PN} = "${PYTHON_PN}-modules"
so all major things are available on the target.
配方结构
我遵循 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
NOTE: I added
setuptools3
since I want my app to be run onpython3.5
. For python2.7 usesetuptools
.
同样,我对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
如果导入抛出没有丢失的模块错误则成功!!
最后的步骤
您可以取消部署模块:
devtool undeploy-target recipe_name [address of target]
将食谱发送给您自定义元层
devtool finish recipe_name ../meta-custom
NOTE: If you are using
krogoth
or lower the you will have to move your recipes to you meta layer manually
- 现在将这些食谱包含在您的
conf/local.conf
中IMAGE_INSTALL_append = " influxdb-python pynmea2"
和bitbake -k your-image-name
自定义应用程序
Not tested yet.
但我想我会像 YoctoCookBook Repository for hello-world
中提到的那样简单地将我的应用程序添加到我的 meta
层。
金块
${PYTHON_PN}-modules
真是救星。我尝试手动添加运行时依赖项,每次我将它部署到板上时,总会缺少一些依赖项。但是添加modules
解决了实例中所有缺失的 deps 问题。我不确定何时使用
DEPENDS_${PN}
但我认为大多数 python 应用程序都依赖于基本python-modules
因此我添加了它们。不是 YOCTO 专家 但这只是我最近两周的发现。 Yocto 中缺少 Python 的适当示例。希望这对某人有所帮助。