Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Python2 and related components completely in Yocto

I am building a custom Linux image in Yocto Zeus (Previously used Yocto Thud). I have moved all the required code to Python3 and hence don't require Python2 anymore. Is there a way we can remove python2 and its modules completely from Image

like image 277
Aashik Aswin Avatar asked Jun 08 '26 00:06

Aashik Aswin


2 Answers

You can use one of these two options

  1. PACKAGE_EXCLUDE: Specifies packages that should not be installed into the image.

    PACKAGE_EXCLUDE_pn-target_image = " python"
    

If you choose to not install a package using this variable and some other package is dependent on it (i.e. listed in a recipe's RDEPENDS variable), the OpenEmbedded build system generates a fatal installation error. Because the build system halts the process with a fatal error, you can use the variable with an iterative development process to remove specific components from a system.

Support for this variable exists only when using the IPK and RPM packaging backend. Support does not exist for DEB. PACKAGE_EXCLUDE definition in Yocto Mega Manual

  1. PNBLACKLIST:

    PNBLACKLIST[python] = "Python2 Not supported by this distro."
    

Lists recipes you do not want the OpenEmbedded build system to build. This variable works in conjunction with the blacklist class, which is inherited globally.

To prevent a recipe from being built, use the PNBLACKLIST variable in your local.conf file. PNBLACKLIST definition in Yocto Mega Manual

like image 52
sob Avatar answered Jun 10 '26 20:06

sob


Start from an image inheriting core-image-minimal and add packages manually. Only the packages that are specified to be installed explicitly in your image recipe and the packages specified in RDEPENDS and RRECOMMENDS of those packages will be installed in the recipe.

Some packages are also pulled because of configuration files (machine, distro or local.conf).

If there are RRECOMMENDS you don't want, you can use BAD_RECOMMENDATIONS in your image recipe to ask the image to not pull them in.

If it's an RDEPENDS that you don't want, maybe it's pulled because of a selected PACKAGECONFIG that you don't need, in that case create a bbappend for that recipe and set PACKAGECONFIG accordingly.

If that still does not do it, you'll have to dig deeper into what can be removed from RDEPENDS and for which reason (is it a mistake? is it safe in one specific configuration in which RDEPENDS is not needed?).

The way to know which package is pulling which package is to use -g as argument of bitbake. Do not attempt to create a scheme/drawing/image from the dot files, they are too big for dot to handle properly (takes hours and the result is unusable). "recipeA:do_foo" => "recipeB:do_bar" means that do_foo task from recipeA depends on do_bar from recipeB.

PACKAGE_EXCLUDE in one of the configuration files (local.conf or distro.conf) should also make it easier to identify which recipe needs the one recipe you don't want.

like image 27
qschulz Avatar answered Jun 10 '26 20:06

qschulz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!