Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Yocto with a distribution using python3 by defaults

More and more Linux distributions use python 3.x as default python, but Yocto still uses python 2.7. How to use Yocto with one of those distributions?

like image 507
Shan-x Avatar asked Sep 13 '25 04:09

Shan-x


2 Answers

Yocto always runs in a virtualenv. But I've found a way to trick it to use python 2 , setting the default python and including it in PATH env variable:

$ source oe-init-build-env build
$ mkdir build/python-bin
$ ln -s /usr/bin/python2 build/python-bin/python
$ ln -s /usr/bin/python2-config build/python-bin/python-config
$ export PATH=$(pwd)/build/python-bin:${PATH}

Thanks all for your help !

like image 171
Shan-x Avatar answered Sep 14 '25 18:09

Shan-x


You can fix it by overwriting the hosttools symlink yocto creates.. I managed to start the yocto build with the fix from Shan-x but it didn't build through.

Yocto sources a different env for all recipes.. Some of the recipes, especially from meta-openembedded require hosttools. These hosttools are for example python (which is then expected to be python2). This hosttools are then symlinked in build/tmp/hosttools and this gets added to $PATH.

python -> /usr/bin/python

to change this to default to python2 just change the symlink to point to /usr/bin/python2

The entire setup:

$ mkdir build/python-bin
$ ln -s /usr/bin/python2 build/python-bin/python
$ ln -s /usr/bin/python2-config build/python-bin/python-config
$ mkdir -p build/tmp/hosttools
$ ln -sf /usr/bin/python2 build/tmp/hosttools/python

to automatically change to python2 add the export $PATH to sources/poky/oe-init-build-env , just before the other stuff gets sourced:

diff --git a/oe-init-build-env b/oe-init-build-env
index e813230a98..c981358577 100755
--- a/oe-init-build-env
+++ b/oe-init-build-env
@@ -47,6 +47,8 @@ if [ -z "$OEROOT" ]; then
 fi
 unset THIS_SCRIPT

+export PATH=$(pwd)/build/python-bin:${PATH}
+
 export OEROOT
 . $OEROOT/scripts/oe-buildenv-internal &&
     TEMPLATECONF="$TEMPLATECONF" $OEROOT/scripts/oe-setup-builddir || {

and then source the env:

$ source oe-init-build-env build
like image 25
stfl Avatar answered Sep 14 '25 17:09

stfl