Python-3.11.2

Introduction to Python 3

The Python 3 package contains the Python development environment. This is useful for object-oriented programming, writing scripts, prototyping large programs or developing entire applications.

[Note]

Note

Python 3 was installed in LFS. The only reason to rebuild it here is if optional modules are needed, or to upgrade this package.

This package is known to build and work properly using an LFS 11.3 platform.

[Important]

Important

If upgrading to a new Python-3 minor version (for example, from Python-3.10.x to Python-3.11.0), you will need to reinstall any Python3 modules you have installed. You should also reinstall packages that generate Python3 modules including gobject-introspection-1.74.0, opencv-4.7.0, Graphviz-7.1.0 (if swig is installed).

Before you upgrade, you can get a complete list of modules installed with pip3 list.

The wheel module and meson from LFS will also have to be reinstalled: https://www.linuxfromscratch.org/lfs/view/development/chapter08/wheel.html and https://www.linuxfromscratch.org/lfs/view/development/chapter08/meson.html.

On systemd systems, it is also necessary to reinstall the MarkupSafe and Jinja2 modules from LFS: https://www.linuxfromscratch.org/lfs/view/systemd/chapter08/markupsafe.html and https://www.linuxfromscratch.org/lfs/view/systemd/chapter08/jinja2.html.

Package Information

Additional Optional Download

Python 3 Dependencies

Recommended

Optional

BlueZ-5.66, GDB-13.1 (required for some tests), Valgrind-3.20.0, and libmpdec

Optional (For Additional Modules)

Berkeley DB-5.3.28, libnsl-2.0.0, and Tk-8.6.13

User Notes: https://wiki.linuxfromscratch.org/blfs/wiki/Python3

Installation of Python 3

Install Python 3 by running the following commands:

CXX="/usr/bin/g++"               \
./configure --prefix=/usr        \
            --enable-shared      \
            --with-system-expat  \
            --with-system-ffi    \
            --enable-optimizations &&
make

To test the result, issue make test. Some tests may need an Internet connection. Two tests, test_distutils and test_embed are known to fail.

Now, as the root user:

make install

If upgrading and the documentation has been downloaded, optionally install it as the root user:

install -v -dm755 /usr/share/doc/python-3.11.2/html

tar --strip-components=1  \
    --no-same-owner       \
    --no-same-permissions \
    -C /usr/share/doc/python-3.11.2/html \
    -xvf ../python-3.11.2-docs-html.tar.bz2

Command Explanations

CXX="/usr/bin/g++" ./configure ...: Avoid an annoying message during configuration.

--with-system-expat: This switch enables linking against the system version of Expat.

--with-system-ffi: This switch enables linking against the system version of libffi.

--with-dbmliborder=bdb:gdbm:ndbm: Use this switch if you want to build the Python DBM Module against Berkeley DB instead of GDBM.

--enable-optimizations: This switch enables stable, but expensive, optimizations.

--with-lto: This optional switch enables thick Link Time Optimization. Unusually, it creates a much larger /usr/lib/python3.11/config-3.11-<arch>-linux-gnu/libpython3.11.a with a small increase in the time to compile Python. Run-time results do not appear to show any benefit from doing this.

Configuring Python 3

In order for python3 to find the installed documentation, create the following version independent symlink:

ln -svfn python-3.11.2 /usr/share/doc/python-3

and add the following environment variable to the individual user's or system's profile:

export PYTHONDOCS=/usr/share/doc/python-3/html

Contents

Installed Programs: 2to3 (symlink) and 2to3-3.11, idle3 (symlink) and idle3.11, pip3 (symlink) and pip3.11, pydoc3 and pydoc3.11, python3 (symlink); python3.11, and python3-config (symlink) and python3.11-config
Installed Libraries: libpython3.11.so and libpython3.so
Installed Directories: /usr/include/python3.11, /usr/lib/python3.11, and /usr/share/doc/python-3.11.2

Short Descriptions

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

pydoc3

is the Python documentation tool

python3

is an interpreted, interactive, object-oriented programming language

python3.11

is a version-specific name for the python program