Gentoo and Python

Gentoo system uses python for its scripts as emerge and therefore the python installation is vital for the system.

Multiple Python Versions

More than one python version is probably installed on a Gentoo system. There needs to be some setup that this works.

When installing the Gentoo-way python scripts seem to end up under /usr/bin however a closer look as ls -l /usr/bin/emerge shows there is just a link to the wrapper script ../lib/python-exec/python-exec2.

Inside ../lib/python-exec/ the script is installed as /usr/lib/python-exec/python3.<n>/<script>

The python-exec wrapper starts those scripts.

The wrapper python-exec hat its configuration file /etc/python-exec/python-exec.conf where global preferences are set.

Packages are in /usr/lib/python<pythonversion>/site-packages and their top level scripts in /usr/lib/python<pythonversion>

When updating and removing an old python version, it can happen that the old directory /usr/lib/python<pythonversion>/site-packages remains, so take a look and delete it.

Python update

There are environmental variables defining what the system supports:

  • portageq envvar PYTHON_TARGETS is a list of the python versions that are supported (it can also return just one version)

  • portageq envvar PYTHON_SINGLE_TARGET shows the python versions to be used

Important

Those variables can change after an emerge --sync

It is unfortunately quite common that Gentoo might get confused when there are python updates. Python updates occur at the same time as other packages updates. A lot of python dependency problems could show up.

To get out of this situation create the file touch /etc/portage/package.use/python and add the following. Then do the procedure:

# instruction to move from python3.<n> to python3.<n+1>

# step 1 do update with old verison
#*/* PYTHON_TARGETS: -* python3_<n>
#*/* PYTHON_SINGLE_TARGET: -* python3_<n>
# emerge --update --newuse --deep --with-bdeps=y @world
# emerge --depclean

# step 2 get also new version
#*/* PYTHON_TARGETS: -* python3_<n> python3_<n+1>
#*/* PYTHON_SINGLE_TARGET: -* python3_<n>
# emerge --update --newuse --deep --with-bdeps=y @world
# emerge --depclean

# step 3 switch single target
#*/* PYTHON_TARGETS: -* python3_<n> python3_<n+1>
#*/* PYTHON_SINGLE_TARGET: -* python3_<n+1>
# emerge --update --newuse --deep --with-bdeps=y @world
# emerge --depclean

# step 4 use just new version
#*/* PYTHON_TARGETS: -* python3_<n+1>
#*/* PYTHON_SINGLE_TARGET: -* python3_<n+1>
# emerge --update --newuse --deep --with-bdeps=y @world
# emerge --depclean

# step5 comment all in this file
# emerge --update --newuse --deep --with-bdeps=y @world
# emerge --depclean

Important

Since the procedure is time consuming it is worth to make a test and start the procedure at step 3. This should update just the packages and not python.

Important

ebuild developers might get surprised when the python3.<n> version suddenly disappears. The Gentoo system might therefore end-up with python modules installed that are not supported by the new python3.<n+1> version. This obviously could give many dependency errors.

  • I simple way out is to stop at step 3 and give the ebuild developers time to do their work. However write a task in the agenda when to continue with step 4 to remove python3.<n>

  • An other way would be adding those ebuilds under /etc/portage/package.use with their dependency to python3.<n>:

    >=<ebuild> python_single_target_python3_<n>

    This could mean lot of work that hopefully soon is obsolete

eix --installed-with-use python_targets_python3_<n> or

equery hasuse python_targets_python3_<n> will show the packages installed support the 3_<n> python version

grep -r python3_<n> /etc/portage/package.use* will show if some packages request a dedicated python version.

Observe what python packages got installed per python version /usr/lib/python3.<n>/site-packages/

See https://wiki.gentoo.org/wiki/Project:Python


Linurs startpage