Since Python is so integral to Gentoo there is little chance it is not installed. Doing so would be like removing the heart from Gentoo. There is occasion where Python must be recompiled in order to add new features or to upgrade.
USE flags for dev-lang/python An interpreted, interactive, object-oriented programming language
||!!internal use only!! DO NOT SET THIS FLAG YOURSELF!, used for creating build images and the first half of bootstrapping [make stage1]||global|
||Install examples, usually source code||global|
||Add support for sys-libs/gdbm (GNU database libraries)||global|
||Activate default security enhancements for toolchain (gcc, glibc, binutils)||global|
||Add support for IP version 6||global|
||Use dev-libs/libressl as SSL provider (might need ssl USE flag), packages should not depend on this USE flag||global|
||Add ncurses support (console display library)||global|
||Enable support for libreadline, a GNU line-editing library that almost everyone wants||global|
||Add support for sqlite - embedded sql database||global|
||Add support for Secure Socket Layer connections||global|
||Enable threading support. (DON'T DISABLE THIS UNLESS YOU KNOW WHAT YOU'RE DOING)||local|
||Add support for Tk GUI toolkit||global|
||Install Windows executables required to create an executable installer for MS Windows.||local|
||Add support for XML files||global|
Python is slotted, which means there is more than one version Python that can be installed on a Gentoo system at the same time. Select the version to install by using an
: (colon) and the package atom followed by one of the slot numbers:
For example, to install Python 3.4:
emerge --ask dev-lang/python:3.4
Setting the active interpreter
The active Python interpreter can be set using the eselect python command. First list the available interpreters using list:
eselect python list
Select the desired interpreter using set. In this example the second option was chosen:
eselect python set 2
The old python-updater is no longer used.
Before starting ensure that the system is up to date:
emerge --ask --update --newuse --deep @world
In order to make system packages be rebuild using the new Python implementation update the PYTHON_TARGETS and PYTHON_SINGLE_TARGET variables in make.conf. For example, when updating from Python 3.4 to 3.5:
PYTHON_TARGETS="python2_7 python3_5" PYTHON_SINGLE_TARGET="python3_5"
Then update the system again using the
--changed-use --deep options to ensure packages using the new Python implementation are
emerge --ask --changed-use --deep @world
You may be asked to update any remaining
python_targets_python3_4 USE flags as well.
Note that many popular packages such as Docker still require PYTHON_SINGLE_TARGET variable to be set to
python2_7 due to various dependencies such as app-text/asciidoc which do not support Python 3.x.
Once the upgrade has completed, old Python implementations can be removed from the system using:
emerge --ask --depclean dev-lang/python
A specific version of the Python interpreter can be invoked from the command-line directly by running:
To execute a script with Python 2.x use the following header:
#!/usr/bin/env python2 ...