Using Yocto with a distribution using python3 by defaults

只谈情不闲聊 提交于 2019-12-14 02:43:31

问题


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?


回答1:


Yocto always runs in a virtualenv. But I've found a way to trick it to use python 3 :

$ 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 !




回答2:


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




回答3:


Linux distributions slowly transfer to Python3 on an application by application basis, by adapting the shebang line to use Python 3.

CentOS 7, Ubuntu 14.4 LTS, Debian Jessy all default to Python2.7 if you type python on the commandline.

If Yocto is installed using a package manager, it will be adapted to whatever works on the Linux distribution it works either with a generic sheband (loading python) or with an explicit one (loading python2 or python2.7.

If you install Yocto yourself, and it might not work because the system you are on defaults to a python from the 3 series, you can adapt the shebang line from:

#!/usr/bin/env python

to

#!/usr/bin/env python2

I assume that python2.7 will be available for a few years to come and installable on demands, even if python3 becomes the default on any of those distributions (just like python3 was available when not installed by default).

What you should consider when installing Yocto from source is run it in a virtualenv so that you setup a clean environment, that might be somewhat more work, depending on the dependencies, but ensures a clean working environment for your application, that cannot be broken by any system update of any packages. And if you do that your setup can even use a python2.7.X version different than that supplied by the Linux distribution.




回答4:


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


来源:https://stackoverflow.com/questions/28360862/using-yocto-with-a-distribution-using-python3-by-defaults

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!