Build

Contents

Build#

This page considers details on building python from source.

Note: The examples in this notebook must be run in the same environment, as they can alter your system’s configuration.

You can download the distribution from the corresponding releases of the official github account.

Check Compile and build section of documentation.

The following cell installs everything needed to build Python, downloads, and extracts the Python version that we’ll use as an example.

apt update &> /dev/null && apt install -y wget gcc make &> /dev/null
[ -d /tmp/installation ] && rm -r /tmp/installation
mkdir /tmp/installation
cd /tmp/installation
wget -q https://github.com/python/cpython/archive/refs/tags/3.8.tar.gz
tar -xzf 3.8.tar.gz
cd cpython-3.8

The resulting Python build may or may not include specific features. This is typically determined during the ./configure step using CLI parameters that start with the word with.

All available options can be checked by running the ./configure --help command.


The following cell displays parts of the ./configure --help command, as the full output is too lengthy.

./configure --help | grep with | head -n 20
  --disable-option-checking  ignore unrecognized --enable/--with options
  --enable-ipv6           Enable ipv6 (with ipv4) support
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-universal-archs=ARCH
  --with-framework-name=FRAMEWORK
                          with --enable-framework
  --with-cxx-main=<compiler>
                          compile main() and link python executable with C++
  --with-suffix=.exe      set executable suffix
  --with-pydebug          build with Py_DEBUG defined
  --with-trace-refs       enable tracing references for debugging purpose
  --with-assertions       build with C assertions enabled
  --with-lto              Enable Link Time Optimization in any build. Disabled
  --with-hash-algorithm=[fnv|siphash24]
  --with-address-sanitizer
  --with-memory-sanitizer enable MemorySanitizer (msan)
  --with-undefined-behavior-sanitizer
  --with-libs='lib1 ...'  link against additional libs
  --with-system-expat     build pyexpat module using an installed expat

Builtin packages#

There is a set of python packages that can only be installed by building python.

Some packages can only be included in the Python build if the corresponding tools are installed on the system. The following table lists some of the required utilities.

Python Module

Purpose

Required System Package(s)

bz2

bzip2 compression

libbz2-dev

lzma

LZMA compression

liblzma-dev (or xz-devel)

ssl

SSL/TLS support

libssl-dev (or openssl-devel)

sqlite3

SQLite support

libsqlite3-dev

_ctypes

C foreign function interface

libffi-dev

tkinter

GUI support with Tk

tk-dev, libtk8.6, libtcl8.6-dev

readline

Command line editing (e.g., input())

libreadline-dev

gdbm

GNU dbm database

libgdbm-dev

dbm.ndbm

Unix ndbm database

libndbm-dev (or part of libc6-dev)

_uuid

UUID support

uuid-dev

zlib

Compression support

zlib1g-dev

_decimal

Decimal floating point

libmpdec-dev

_sqlite3

SQLite bindings

libsqlite3-dev

_ssl

SSL module

libssl-dev

_hashlib

Hashing (SHA, MD5)

libssl-dev

_tkinter

GUI support

tk-dev, tcl-dev

_curses

Terminal handling

libncursesw5-dev

_bz2

bzip2 support

libbz2-dev

_lzma

xz compression

liblzma-dev

termios, fcntl, etc.

Terminal and system call interfaces

Usually always built on Unix

Here are the parameters required for package installation, the absence of which caused some problems in my practice:

  • --with-ensurepip: garantees that python will have the ensurepip package, which installes pip in python and possble virtual environments.

  • --with-ssl-default-sites=openssl to include the ssl module in the build.