Using Yocto with a distribution using python3 by defaults

12,237

Solution 1

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 !

Solution 2

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

Solution 3

The canonical solution here is to use virtualenv to create an environment where "python" is python 2.

Share:
12,237
Shan-x
Author by

Shan-x

Updated on August 03, 2022

Comments

  • Shan-x
    Shan-x almost 2 years

    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?

  • stfl
    stfl over 6 years
    this doesn't work because bitbake requires python3.. 0o
  • Ross Burton
    Ross Burton over 6 years
    But the question was specifically about releases where yocto uses py2.
  • stfl
    stfl over 6 years
    the problem also stands for current yocto releases... bitbake needs python3 and some of the internal recipies from openembedded require python to be python2... if you set an virtualenv for only python2, bitbake does not run... I ran into the same problem and there is some hardcoding done inside of some of the oe recipes symlinking it to the hosttools...
  • Ross Burton
    Ross Burton over 6 years
    Yocto doesn't run in a virtualenv by default.
  • Shan-x
    Shan-x over 6 years
    I'm not using Yocto anymore, so I'm not sure. But the doc states that "the recommend usage is to install these dependencies in a Python virtual environment using pip.".