List all Gentoo packages built against the old python or specific version

Author:

Updating python under Gentoo is not always straightforward work. Despite a clean upgrade without any blockers or masked packages, sometimes, on old machines, there might be packages left still built against an old version of python, which is no longer available on the system!

main menu
Query for USE with python_targets_python3_4, python_targets_python3_5 and python_targets_python3_6.

On Gentoo, there are two important flags in the configuration make.conf file:

PYTHON_TARGETS="python3_8 python3_10"
PYTHON_SINGLE_TARGET="python3_8"

The PYTHON_TARGETS and PYTHON_SINGLE_TARGET control the support of multiple Python versions installed on the system. When the Gentoo package has a use flag python, the builder emerge will build the python module for all the Python versions in PYTHON_TARGETS. Some programs or libraries may not support multiple versions to be installed on the system and they may require to specify just one Python library target, against which they are going to be built and that’s why PYTHON_SINGLE_TARGET exists. In most cases, the PYTHON_SINGLE_TARGET should be the active (default in the system) Python version.

When building the Gentoo packages expand these variables as USE flags of the kind – python_targets_python3_8 and python_targets_python3_10. So the user may search for Gentoo installed packages with USE flags python_targets_python3_8 and python_targets_python3_10 or older like python_targets_python3_6, which may be left from previous installations.
For example, to search installed Gentoo packages, which are built against Python version 3.6, search for USE flags python_targets_python3_6 using the equerytool from app-portage/gentoolkit.
First, install the equery tool by building the package app-portage/gentoolkit:

emerge -va app-portage/gentoolkit

And then, search for packages with:

root@srv ~ # equery h python_targets_python3_6
 * Searching for USE flag python_targets_python3_6 ... 
[I--] [??] app-portage/gentoolkit-0.5.0-r2:0
[I--] [??] dev-libs/boost-1.74.0-r1:0/1.74.0
[I--] [??] dev-libs/gobject-introspection-1.56.1:0
[IP-] [  ] dev-libs/libnl-3.5.0:3
[I--] [??] dev-python/cffi-1.14.4:0/1.14.4
[I--] [??] dev-python/chardet-3.0.4-r1:0
[I--] [??] dev-python/cryptography-3.2.1:0
[I--] [??] dev-python/docutils-0.16-r1:0
[I--] [??] dev-python/mako-1.1.3-r1:0
[IP-] [  ] dev-python/markupsafe-1.1.1-r1:0
[I--] [??] dev-python/mysqlclient-1.4.6-r1:0
[I--] [??] dev-python/ply-3.11-r1:0/3.11
[I--] [??] dev-python/pycparser-2.20-r1:0
[I--] [??] dev-python/pygments-2.7.3:0
[I--] [??] dev-python/pyinotify-0.9.6:0
[I--] [??] dev-python/pyopenssl-20.0.0-r1:0
[I--] [??] dev-python/pyxattr-0.7.1:0
[I--] [??] dev-util/glib-utils-2.56.2:0
[IP-] [  ] sys-libs/cracklib-2.9.7:0
[I--] [??] sys-libs/libcap-ng-0.8:0
[I--] [??] sys-process/audit-2.8.3:0
[I--] [??] x11-base/xcb-proto-1.13:0

As shown, there are 22 packages, in which Python modules are still built against the old Python 3.6 version, which may not even exist anymore on the system!
It’s worth mentioning, that the above packages may be built not only against one but multiple Python versions thanks to multiple versions in PYTHON_TARGETS. So the modules above may function properly for the Python versions, which are still in use in the system.

All of the above packages should be rebuilt if Python 3.6 is not installed (i.e. it was removed from the system) or is not going to be removed because the user removed it from the PYTHON_TARGETS and PYTHON_SINGLE_TARGET.
Most of the above packages may have newer versions and here is how to check what Python version they support:

root@srv ~ # equery u dev-python/cryptography
[ Legend : U - final flag setting for installation]
[        : I - package is installed with flag     ]
[ Colors : set, unset                             ]
 * Found these USE flags for dev-python/cryptography-38.0.2:
 U I
 - - debug                     : Enable extra debug codepaths, like asserts and extra output. If you want to
                                 get meaningful backtraces see
                                 https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
 - - python_targets_pypy3      : Build with PyPy3
 + + python_targets_python3_10 : Build with Python 3.10
 - - python_targets_python3_11 : Build with Python 3.11
 + + python_targets_python3_8  : Build with Python 3.8
 - - python_targets_python3_9  : Build with Python 3.9
 - - test                      : Enable dependencies and/or preparations necessary to run tests (usually
                                 controlled by FEATURES=test but can be toggled independently)

So the new version of the Python module cryptography may be built only against Python versions 3.8, 3.9, 3.10, and 3.11.

After the Python upgrade in Gentoo always check with equery for modules and packages built against the old Python versions. Check out the very similar Ruby version of this article – List all Gentoo packages built against the old ruby or specific version

Leave a Reply

Your email address will not be published. Required fields are marked *