Search code examples
pythonlinuxyoctottymeta-raspberrypi

Not able to import python tty module in raspberry pi yocto build


Description

Error while python tty module.

How to enable this module in yocto build ?

Environment

root@raspberrypi3-64:~# uname -a
Linux raspberrypi3-64 5.4.83-v8 #1 SMP PREEMPT Wed Jan 20 09:59:41 UTC 2021 aarch64 GNU/Linux

Log

root@raspberrypi3-64:~# python3
Python 3.9.1 (default, Dec  7 2020, 22:33:43) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tty
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tty'
>>> 
root@raspberrypi3-64:~# 

Expected output

The tty module should be imported similar to the following Log from the ubuntu 18.04 host

~$ python3
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tty
>>> 
~$ 

Solution

  • The python3 recipe is a bit different than others, so it's not always straightforward to find which packages it builds and their name.

    For Python standard libraries, such as tty, logging, 2to3, datetime, one has to read the python3-manifest.json file used in the python3 recipe, see http://cgit.openembedded.org/openembedded-core/tree/meta/recipes-devtools/python/python3/python3-manifest.json?h=master

    There, you can see that tty.py is part of the terminal dictionary. All first level key (terminal included) in the "root" dictionary will be the suffix for the package that will be created. In terminal case, it'll thus be python3-terminal. Which means if one wants tty module on their target, they should add the python3-terminal to their image recipe.

    This specific logic of package splitting the standard libraries of Python was a consequence of Python with all its libraries being outrageously big for embedded systems where usually the set of libraries used can be defined and fixed or updated by hand.