如何让 Yocto 构建模块 fcntl 作为 Python 构建的一部分

How to have Yocto build Module fcntl as part of Python Build

我使用 Yocto 在 Ubuntu x86、Raspberry Pi、BeagleBone Black 和 TI AM57XX EVM(开发​​套件). Python-Twisted 导入上述所有机器都没有问题,除了 AM57XX Dev Kit。它吐出以下错误:

Python 2.7.11 (default, Aug  7 2017, 12:07:27)
[GCC 5.3.1 20160113] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from txdbus import client,error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/txdbus/client.py", line 11, in <module>
    from twisted.internet import defer, reactor
  File "/usr/lib/python2.7/site-packages/twisted/internet/reactor.py", line 39, in <module>
  File "/usr/lib/python2.7/site-packages/twisted/internet/epollreactor.py", line 405, in install
  File "/usr/lib/python2.7/site-packages/twisted/internet/epollreactor.py", line 235, in __init__
  File "/usr/lib/python2.7/site-packages/twisted/internet/base.py", line 498, in __init__
  File "/usr/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 289, in installWaker
  File "/usr/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 139, in __init__
  File "/usr/lib/python2.7/site-packages/twisted/internet/fdesc.py", line 25, in setNonBlocking
AttributeError: 'NoneType' object has no attribute 'fcntl'

如果我在开发板上启动Python并尝试导入fcntl模块,它确实丢失了:

Python 2.7.11 (default, Aug  7 2017, 12:07:27)
[GCC 5.3.1 20160113] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import fcntl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named fcntl

每台机器上的包列表都是一样的。我错过了什么?是否需要对内核进行不同的配置?

当我在谷歌上搜索时,我发现了这个 post: https://lists.yoctoproject.org/pipermail/yocto/2013-May/013953.html

似乎表明来自 Yocto 的 Python 有问题并且配置错误,因此它不包含 fcntl 模块:

>> ImportError: No module named fcntl
>> ========
>> 
>> So it looks like the Python included with the SDK is crippled or mis-configured:
> 
> Yeah, the Python we build is split up massively, so clearly the SDK is
> missing the packages that are needed to run bitbake.  But as I said,
> using our SDK to build is over-complicating things as Ubuntu should
> work fine.  What problems were you seeing?

当 Yocto 构建 Python 时,log.do_package 脚本提到 python-fcntl 所需的依赖项 - 但它们看起来不像错误:

log.do_package:DEBUG: runstrip: 'arm-linux-gnueabihf-strip' --remove-section=.comment --remove-section=.note --strip-unneeded '/home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/package/usr/lib/python2.7/lib-dynload/fcntl.so'
log.do_package:DEBUG: LIBNAMES: pkg python-fcntl libs 0 bins 0 sonames []
log.do_package:DEBUG: calculating shlib provides for python-fcntl
log.do_package:DEBUG: LIBNAMES: pkg python-fcntl sonames []
log.do_package:DEBUG: calculating shlib requirements for python-fcntl
log.do_package:DEBUG: python-fcntl: Dependency libpython2.7.so.1.0 requires package libpython2 (used by files: /home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/packages-split/python-fcntl/usr/lib/python2.7/lib-dynload/fcntl.so)
log.do_package:DEBUG: python-fcntl: Dependency libc.so.6 requires package external-linaro-toolchain (used by files: /home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/packages-split/python-fcntl/usr/lib/python2.7/lib-dynload/fcntl.so)
log.do_package.17147:DEBUG: runstrip: 'arm-linux-gnueabihf-strip' --remove-section=.comment --remove-section=.note --strip-unneeded '/home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/package/usr/lib/python2.7/lib-dynload/fcntl.so'
log.do_package.17147:DEBUG: LIBNAMES: pkg python-fcntl libs 0 bins 0 sonames []
log.do_package.17147:DEBUG: calculating shlib provides for python-fcntl
log.do_package.17147:DEBUG: LIBNAMES: pkg python-fcntl sonames []
log.do_package.17147:DEBUG: calculating shlib requirements for python-fcntl
log.do_package.17147:DEBUG: python-fcntl: Dependency libpython2.7.so.1.0 requires package libpython2 (used by files: /home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/packages-split/python-fcntl/usr/lib/python2.7/lib-dynload/fcntl.so)
log.do_package.17147:DEBUG: python-fcntl: Dependency libc.so.6 requires package external-linaro-toolchain (used by files: /home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/packages-split/python-fcntl/usr/lib/python2.7/lib-dynload/fcntl.so)
log.do_populate_sysroot:DEBUG: runstrip: 'arm-linux-gnueabihf-strip' --remove-section=.comment --remove-section=.note --strip-unneeded '/home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/sysroot-destdir/usr/lib/python2.7/lib-dynload/fcntl.so'
log.do_populate_sysroot.17148:DEBUG: runstrip: 'arm-linux-gnueabihf-strip' --remove-section=.comment --remove-section=.note --strip-unneeded '/home/me/am57xx/build/tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/python/2.7.11-r1/sysroot-destdir/usr/lib/python2.7/lib-dynload/fcntl.so'

所以我认为它构建了模块但无法将其打包到我的根文件系统中。

我下载了 Python 源代码和 运行 使用 "help" 配置并搜索了 fcntl。

./configure --help | grep fcntl

然而,没有任何结果!

我可以对我的 Yocto 配置或 Python 方法做些什么来将 fcntl 部署到根文件系统?

使用 Yocto 的最新配方构建最新的 Python 2.7.

这是一个旧线程,但我不得不上下搜索这个主题才能解决它。

在我的 Yocto“poky”构建中,fcntl 在目标设备上

/usr/lib/python2.7/lib-dynload/fcntl.so

Yocto 重新排列并删除了一些 python 模块以保存 space,包括我发行版中的子进程和 fcntl。

要添加它,找到任何创建图像的 bb/inc 文件,添加以下内容

IMAGE_INSTALL_append = " python-fcntl "

然后重建 rootfs 或最终映像。该文件应出现在

./build/tmp/.../rootfs/usr/lib/python2.7/lib-dynload/fcntl.so

您可以将此文件复制到您的目标机器上进行测试。