3. Configure Python

3.1. Build Requirements

To build CPython, you will need:

Changed in version 3.5: On Windows, Visual Studio 2015 or later is now required.

Changed in version 3.6: Selected C99 features, like <stdint.h> and static inline functions, are now required.

Changed in version 3.7: Thread support is now required.

Changed in version 3.11: C11 compiler, IEEE 754 and NaN support are now required. On Windows, Visual Studio 2017 or later is required.

See also PEP 7 “Style Guide for C Code” and PEP 11 “CPython platform support”.

3.1.1. Requirements for optional modules

Some optional modules of the standard library require third-party libraries installed for development (for example, header files must be available).

Missing requirements are reported in the configure output. Modules that are missing due to missing dependencies are listed near the end of the make output, sometimes using an internal name, for example, _ctypes for ctypes module.

If you distribute a CPython interpreter without optional modules, it’s best practice to advise users, who generally expect that standard library modules are available.

Dependencies to build optional modules are:

Dependency

Minimum version

Python module

libbz2

bz2

libffi

3.3.0 recommended

ctypes

liblzma

lzma

libmpdec

2.5.0

decimal [1]

libreadline or libedit [2]

readline

libuuid

_uuid [3]

ncurses [4]

curses

OpenSSL

3.0.18 recommended
(1.1.1 minimum)

ssl, hashlib [5]

SQLite

3.15.2

sqlite3

Tcl/Tk

8.5.12

tkinter, IDLE, turtle

zlib

1.2.2.1

zlib, gzip, ensurepip

zstd

1.4.5

compression.zstd

Note that the table does not include all optional modules; in particular, platform-specific modules like winreg are not listed here.

See also

Changed in version 3.1: Tcl/Tk version 8.3.1 is now required for tkinter.

Changed in version 3.5: Tcl/Tk version 8.4 is now required for tkinter.

Changed in version 3.7: OpenSSL 1.0.2 is now required for hashlib and ssl.

Changed in version 3.10: OpenSSL 1.1.1 is now required for hashlib and ssl. SQLite 3.7.15 is now required for sqlite3.

Changed in version 3.11: Tcl/Tk version 8.5.12 is now required for tkinter.

Changed in version 3.13: SQLite 3.15.2 is now required for sqlite3.

3.2. Generated files

To reduce build dependencies, Python source code contains multiple generated files. Commands to regenerate all generated files:

make regen-all
make regen-stdlib-module-names
make regen-limited-abi
make regen-configure

The Makefile.pre.in file documents generated files, their inputs, and tools used to regenerate them. Search for regen-* make targets.

3.2.1. configure script

The make regen-configure command regenerates the aclocal.m4 file and the configure script using the Tools/build/regen-configure.sh shell script which uses an Ubuntu container to get the same tools versions and have a reproducible output.

The container is optional, the following command can be run locally:

autoreconf -ivf -Werror

The generated files can change depending on the exact versions of the tools used. The container that CPython uses has Autoconf 2.72, aclocal from Automake 1.16.5, and pkg-config 1.8.1.

Changed in version 3.13: Autoconf 2.71 and aclocal 1.16.5 and are now used to regenerate configure.

Changed in version 3.14: Autoconf 2.72 is now used to regenerate configure.

3.3. Configure Options

List all configure script options using:

./configure --help

See also the Misc/SpecialBuilds.txt in the Python source distribution.

3.3.1. General Options

--enable-loadable-sqlite-extensions

Support loadable extensions in the _sqlite extension module (default is no) of the sqlite3 module.

See the sqlite3.Connection.enable_load_extension() method of the sqlite3 module.

Added in version 3.6.

--disable-ipv6

Disable IPv6 support (enabled by default if supported), see the socket module.

--enable-big-digits=[15|30]

Define the size in bits of Python int digits: 15 or 30 bits.

By default, the digit size is 30.

Define the PYLONG_BITS_IN_DIGIT to 15 or 30.

See sys.int_info.bits_per_digit.

--with-suffix=SUFFIX

Set the Python executable suffix to SUFFIX.

The default suffix is .exe on Windows and macOS (python.exe executable), .js on Emscripten node, .html on Emscripten browser, .wasm on WASI, and an empty string on other platforms (python executable).

Changed in version 3.11: The default suffix on WASM platform is one of .js, .html or .wasm.

--with-tzpath=<list of absolute paths separated by pathsep>

Select the default time zone search path for zoneinfo.TZPATH. See the Compile-time configuration of the zoneinfo module.

Default: /usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo.

See os.pathsep path separator.

Added in version 3.9.

--without-decimal-contextvar

Build the _decimal extension module using a thread-local context rather than a coroutine-local context (default), see the decimal module.

See decimal.HAVE_CONTEXTVAR and the contextvars module.

Added in version 3.9.

--with-dbmliborder=<list of backend names>

Override order to check db backends for the dbm module

A valid value is a colon (:) separated string with the backend names:

  • ndbm;

  • gdbm;

  • bdb.

--without-c-locale-coercion

Disable C locale coercion to a UTF-8 based locale (enabled by default).

Don’t define the PY_COERCE_C_LOCALE macro.

See PYTHONCOERCECLOCALE and the PEP 538.

--with-platlibdir=DIRNAME

Python library directory name (default is lib).

Fedora and SuSE use lib64 on 64-bit platforms.

See sys.platlibdir.

Added in version 3.9.

--with-wheel-pkg-dir=PATH

Directory of wheel packages used by the ensurepip module (none by default).

Some Linux distribution packaging policies recommend against bundling dependencies. For example, Fedora installs wheel packages in the /usr/share/python-wheels/ directory and don’t install the ensurepip._bundled package.

Added in version 3.10.

--with-pkg-config=[check|yes|no]

Whether configure should use pkg-config to detect build dependencies.

  • check (default): pkg-config is optional

  • yes: pkg-config is mandatory

  • no: configure does not use pkg-config even when present

Added in version 3.11.

--with-missing-stdlib-config=FILE

Path to a JSON configuration file containing custom error messages for missing standard library modules.

This option is intended for Python distributors who wish to provide distribution-specific guidance when users encounter standard library modules that are missing or packaged separately.

The JSON file should map missing module names to custom error message strings. For example, if your distribution packages tkinter and _tkinter separately and excludes _gdbm for legal reasons, the configuration could contain:

{
    "_gdbm": "The '_gdbm' module is not available in this distribution",
    "tkinter": "Install the python-tk package to use tkinter",
    "_tkinter": "Install the python-tk package to use tkinter",
}

Added in version 3.15.

--enable-pystats

Turn on internal Python performance statistics gathering.

By default, statistics gathering is off. Use python3 -X pystats command or set PYTHONSTATS=1 environment variable to turn on statistics gathering at Python startup.

At Python exit, dump statistics if statistics gathering was on and not cleared.

Effects:

  • Add -X pystats command line option.

  • Add PYTHONSTATS environment variable.

  • Define the Py_STATS macro.

  • Add functions to the sys module:

    • sys._stats_on(): Turns on statistics gathering.

    • sys._stats_off(): Turns off statistics gathering.

    • sys._stats_clear(): Clears the statistics.

    • sys._stats_dump(): Dump statistics to file, and clears the statistics.

The statistics will be dumped to a arbitrary (probably unique) file in /tmp/py_stats/ (Unix) or C:\temp\py_stats\ (Windows). If that directory does not exist, results will be printed on stderr.

Use Tools/scripts/summarize_stats.py to read the stats.

Statistics:

  • Opcode:

    • Specialization: success, failure, hit, deferred, miss, deopt, failures;

    • Execution count;

    • Pair count.

  • Call:

    • Inlined Python calls;

    • PyEval calls;

    • Frames pushed;

    • Frame object created;

    • Eval calls: vector, generator, legacy, function VECTORCALL, build class, slot, function “ex”, API, method.

  • Object:

    • incref and decref;

    • interpreter incref and decref;

    • allocations: all, 512 bytes, 4 kiB, big;

    • free;

    • to/from free lists;

    • dictionary materialized/dematerialized;

    • type cache;

    • optimization attempts;

    • optimization traces created/executed;

    • uops executed.

  • Garbage collector:

    • Garbage collections;

    • Objects visited;

    • Objects collected.

Added in version 3.11.

--disable-gil

Enables support for running Python without the global interpreter lock (GIL): free-threaded build.

Defines the Py_GIL_DISABLED macro and adds "t" to sys.abiflags.

See Free-threaded CPython for more detail.

Added in version 3.13.

--enable-experimental-jit=[no|yes|yes-off|interpreter]

Indicate how to integrate the experimental just-in-time compiler.

  • no: Don’t build the JIT.

  • yes: Enable the JIT. To disable it at runtime, set the environment variable PYTHON_JIT=0.

  • yes-off: Build the JIT, but disable it by default. To enable it at runtime, set the environment variable PYTHON_JIT=1.

  • interpreter: Enable the “JIT interpreter” (only useful for those debugging the JIT itself). To disable it at runtime, set the environment variable PYTHON_JIT=0.

--enable-experimental-jit=no is the default behavior if the option is not provided, and --enable-experimental-jit is shorthand for --enable-experimental-jit=yes. See Tools/jit/README.md for more information, including how to install the necessary build-time dependencies.

Note

When building CPython with JIT enabled, ensure that your system has Python 3.11 or later installed.

Added in version 3.13.

PKG_CONFIG

Path to pkg-config utility.

PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH

pkg-config options.

--disable-epoll

Build without epoll, meaning that select.epoll() will not be present even if the system provides an epoll_create function. This may be used on systems where epoll_create or epoll_create1 is available but incompatible with Linux semantics.

Added in version 3.15.

3.3.2. C compiler options

CC

C compiler command.

CFLAGS

C compiler flags.

CPP

C preprocessor command.

CPPFLAGS

C preprocessor flags, e.g. -Iinclude_dir.

3.3.3. Linker options

LDFLAGS

Linker flags, e.g. -Llibrary_directory.

LIBS

Libraries to pass to the linker, e.g. -llibrary.

MACHDEP

Name for machine-dependent library files.

3.3.4. Options for third-party dependencies

Added in version 3.11.

BZIP2_CFLAGS
BZIP2_LIBS

C compiler and linker flags to link Python to libbz2, used by bz2 module, overriding pkg-config.