8.60. Python-3.13.2

The Python 3 package contains the Python development environment. It is useful for object-oriented programming, writing scripts, prototyping large programs, and developing entire applications. Python is an interpreted computer language.

Approximate build time: 2.1 SBU
Required disk space: 501 MB

8.60.1. Installation of Python 3

Create the PKGBUILD for the Python package with the following commands:

mkdir /sources/python
cd /sources/python
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="python"
pkgver="3.13.2"
pkgrel="1"
pkgdesc="The Python 3 package contains the Python development environment."
arch=('x86'
      'x86_64')
url="https://www.python.org/"
license=('PSFLv2')
groups=('core')
depends=('bzip2'
         'expat'
         'gdbm'
         'glibc'
         'libffi'
         'libnsl'
         'libxcrypt'
         'ncurses'
         'openssl'
         'rootfs'
         'sqlite'
         'zlib')
makedepends=('bash'
             'binutils'
             'coreutils'
             'gcc'
             'gettext'
             'grep'
             'make'
             'pkgconf'
             'sed'
             'util-linux')
checkdepends=('gdb'
              'valgrind')
optdepends=('berkeley-db'
            'tk')
source=('https://www.python.org/ftp/python/3.13.2/Python-3.13.2.tar.xz'
        'https://www.python.org/ftp/python/doc/3.13.2/python-3.13.2-docs-html.tar.bz2')
md5sums=('4c2d9202ab4db02c9d0999b14655dfe5'
         'd6aede88f480a018d26b3206f21654ae')
    
build(){
  cd ${_pkgname}-${pkgver}
  ./configure --prefix=/usr        \
              --enable-shared      \
              --with-system-expat  \
              --without-ensurepip  \
              --enable-optimizations
  make
}

check(){
  cd ${_pkgname}-${pkgver}
  make test TESTOPTS="--timeout 120"
}

package(){
  cd ${_pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install

  # Install the Python documentation
  install -v -dm755 ${pkgdir}/usr/share/doc/${pkgname}-${pkgver}/html
  tar --strip-components=1  \
      --no-same-owner       \
      --no-same-permissions \
      -C ${pkgdir}/usr/share/doc/${pkgname}-${pkgver}/html \
      -xvf ${srcdir}/${pkgname}-${pkgver}-docs-html.tar.bz2

  # Remove pycache from pkgdir
  for dir in `find ${pkgdir} -name __pycache__`; do
    rm -rf $dir
  done
}
REALEOF

The meaning of the configure and install options:

--without-ensurepip

This switch ensures that pip is not built as part of our Python installation. Unlike in the upackaged LFS, the pip package will be installed separately.

--with-system-expat

This switch enables linking against the system version of Expat.

--enable-optimizations

This switch enables extensive, but time-consuming, optimization steps. The interpreter is built twice; tests performed on the first build are used to improve the optimized final version.

--no-same-owner and --no-same-permissions

Ensure the installed files have the correct ownership and permissions. Without these options, tar will install the package files with the upstream creator's values.

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp python-3.13.2-1-$(uname -m).pkg.tar.xz \                           /srv/pacman/repos/LFS/                                                                                               repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \                                                                                   /srv/pacman/repos/LFS/python-3.13.2-1-$(uname -m).pkg.tar.xz

Update the local cache and install the Python package:

pacman -Syu
pacman -S python --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/python
cp PKGBUILD /srv/pacman/source/LFS/python
cd /sources
rm -rf python

8.60.2. Contents of Python 3

Installed programs: 2to3, idle3, pip3, pydoc3, python3, and python3-config
Installed library: libpython3.13.so and libpython3.so
Installed directories: /usr/include/python3.13, /usr/lib/python3, and /usr/share/doc/python-3.13.2

Short Descriptions

2to3

is a Python program that reads Python 2.x source code and applies a series of fixes to transform it into valid Python 3.x code

idle3

is a wrapper script that opens a Python aware GUI editor. For this script to run, you must have installed Tk before Python, so that the Tkinter Python module is built.

pip3

The package installer for Python. You can use pip to install packages from Python Package Index and other indexes.

pydoc3

is the Python documentation tool

python3

is the interpreter for Python, an interpreted, interactive, object-oriented programming language