3. Configure Python¶
3.1. Build Requirements¶
To build CPython, you will need:
A C11 compiler. Optional C11 features are not required.
On Windows, Microsoft Visual Studio 2017 or later is required.
Support for IEEE 754 floating-point numbers and floating-point Not-a-Number (NaN).
Support for threads.
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 |
|---|---|---|
3.3.0 recommended |
||
2.5.0 |
||
|
||
3.0.18 recommended
(1.1.1 minimum)
|
||
3.15.2 |
||
8.5.12 |
||
1.2.2.1 |
||
1.4.5 |
Note that the table does not include all optional modules; in particular,
platform-specific modules like winreg are not listed here.
See also
The devguide includes a full list of dependencies required to build all modules and instructions on how to install them on common platforms.
--with-system-expatallows building with an external libexpat library.
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.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
_sqliteextension module (default is no) of thesqlite3module.See the
sqlite3.Connection.enable_load_extension()method of thesqlite3module.Added in version 3.6.
- --enable-big-digits=[15|30]¶
Define the size in bits of Python
intdigits: 15 or 30 bits.By default, the digit size is 30.
Define the
PYLONG_BITS_IN_DIGITto15or30.
- --with-suffix=SUFFIX¶
Set the Python executable suffix to SUFFIX.
The default suffix is
.exeon Windows and macOS (python.exeexecutable),.json Emscripten node,.htmlon Emscripten browser,.wasmon WASI, and an empty string on other platforms (pythonexecutable).Changed in version 3.11: The default suffix on WASM platform is one of
.js,.htmlor.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 thezoneinfomodule.Default:
/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo.See
os.pathseppath separator.Added in version 3.9.
- --without-decimal-contextvar¶
Build the
_decimalextension module using a thread-local context rather than a coroutine-local context (default), see thedecimalmodule.See
decimal.HAVE_CONTEXTVARand thecontextvarsmodule.Added in version 3.9.
- --with-dbmliborder=<list of backend names>¶
Override order to check db backends for the
dbmmoduleA 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_LOCALEmacro.See
PYTHONCOERCECLOCALEand the PEP 538.
- --with-platlibdir=DIRNAME¶
Python library directory name (default is
lib).Fedora and SuSE use
lib64on 64-bit platforms.See
sys.platlibdir.Added in version 3.9.
- --with-wheel-pkg-dir=PATH¶
Directory of wheel packages used by the
ensurepipmodule (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 theensurepip._bundledpackage.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 optionalyes: pkg-config is mandatoryno: configure does not use pkg-config even when present
Added in version 3.11.
- --enable-pystats¶
Turn on internal Python performance statistics gathering.
By default, statistics gathering is off. Use
python3 -X pystatscommand or setPYTHONSTATS=1environment 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 pystatscommand line option.Add
PYTHONSTATSenvironment variable.Define the
Py_STATSmacro.Add functions to the
sysmodule: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) orC:\temp\py_stats\(Windows). If that directory does not exist, results will be printed on stderr.Use
Tools/scripts/summarize_stats.pyto 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 threading build.
Defines the
Py_GIL_DISABLEDmacro and adds"t"tosys.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 variablePYTHON_JIT=0.yes-off: Build the JIT, but disable it by default. To enable it at runtime, set the environment variablePYTHON_JIT=1.interpreter: Enable the “JIT interpreter” (only useful for those debugging the JIT itself). To disable it at runtime, set the environment variablePYTHON_JIT=0.
--enable-experimental-jit=nois the default behavior if the option is not provided, and--enable-experimental-jitis shorthand for--enable-experimental-jit=yes. SeeTools/jit/README.mdfor 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-configutility.
- PKG_CONFIG_LIBDIR¶
- PKG_CONFIG_PATH¶
pkg-configoptions.
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 bybz2module, overridingpkg-config.
- CURSES_CFLAGS¶
- CURSES_LIBS¶
C compiler and linker flags for
libncursesorlibncursesw, used bycursesmodule, overridingpkg-config.
- GDBM_CFLAGS¶
- GDBM_LIBS¶
C compiler and linker flags for
gdbm.
- LIBEDIT_CFLAGS¶
- LIBEDIT_LIBS¶
C compiler and linker flags for
libedit, used byreadlinemodule, overridingpkg-config.
- LIBFFI_CFLAGS¶
- LIBMPDEC_CFLAGS¶
- LIBMPDEC_LIBS¶
C compiler and linker flags for
libmpdec, used bydecimalmodule, overridingpkg-config.Note
These environment variables have no effect unless
--with-system-libmpdecis specified.
- LIBLZMA_CFLAGS¶
- LIBREADLINE_CFLAGS¶
- LIBREADLINE_LIBS¶
C compiler and linker flags for
libreadline, used byreadlinemodule, overridingpkg-config.
- LIBSQLITE3_CFLAGS¶
- LIBSQLITE3_LIBS¶
C compiler and linker flags for
libsqlite3, used bysqlite3module, overridingpkg-config.
- LIBUUID_CFLAGS¶
- LIBZSTD_CFLAGS¶
- LIBZSTD_LIBS¶
C compiler and linker flags for
libzstd, used bycompression.zstdmodule, overridingpkg-config.Added in version 3.14.
- PANEL_CFLAGS¶
- PANEL_LIBS¶
C compiler and linker flags for PANEL, overriding
pkg-config.C compiler and linker flags for
libpanelorlibpanelw, used bycurses.panelmodule, overridingpkg-config.
- TCLTK_CFLAGS¶
- TCLTK_LIBS¶
C compiler and linker flags for TCLTK, overriding
pkg-config.
- ZLIB_CFLAGS¶
3.3.5. WebAssembly Options¶
- --enable-wasm-dynamic-linking¶
Turn on dynamic linking support for WASM.
Dynamic linking enables
dlopen. File size of the executable increases due to limited dead code elimination and additional features.Added in version 3.11.
- --enable-wasm-pthreads¶
Turn on pthreads support for WASM.
Added in version 3.11.
3.3.6. Install Options¶
- --prefix=PREFIX¶
Install architecture-independent files in PREFIX. On Unix, it defaults to
/usr/local.This value can be retrieved at runtime using
sys.prefix.As an example, one can use
--prefix="$HOME/.local/"to install a Python in its home directory.
- --exec-prefix=EPREFIX¶
Install architecture-dependent files in EPREFIX, defaults to
--prefix.This value can be retrieved at runtime using
sys.exec_prefix.
3.3.7. Performance options¶
Configuring Python using --enable-optimizations --with-lto (PGO + LTO) is
recommended for best performance. The experimental --enable-bolt flag can
also be used to improve performance.
- --enable-optimizations¶
Enable Profile Guided Optimization (PGO) using
PROFILE_TASK(disabled by default).The C compiler Clang requires
llvm-profdataprogram for PGO. On macOS, GCC also requires it: GCC is just an alias to Clang on macOS.Disable also semantic interposition in libpython if
--enable-sharedand GCC is used: add-fno-semantic-interpositionto the compiler and linker flags.Note
During the build, you may encounter compiler warnings about profile data not being available for some source files. These warnings are harmless, as only a subset of the code is exercised during profile data acquisition. To disable these warnings on Clang, manually suppress them by adding
-Wno-profile-instr-unprofiledtoCFLAGS.Added in version 3.6.
Changed in version 3.10: Use
-fno-semantic-interpositionon GCC.
- PROFILE_TASK¶
Environment variable used in the Makefile: Python command line arguments for the PGO generation task.
Default:
-m test --pgo --timeout=$(TESTTIMEOUT).Added in version 3.8.
Changed in version 3.13: Task failure is no longer ignored silently.
- --with-lto=[full|thin|no|yes]¶
Enable Link Time Optimization (LTO) in any build (disabled by default).
The C compiler Clang requires
llvm-arfor LTO (aron macOS), as well as an LTO-aware linker (ld.goldorlld).Added in version 3.6.
Added in version 3.11: To use ThinLTO feature, use
--with-lto=thinon Clang.Changed in version 3.12: Use ThinLTO as the default optimization policy on Clang if the compiler accepts the flag.
- --enable-bolt¶
Enable usage of the BOLT post-link binary optimizer (disabled by default).
BOLT is part of the LLVM project but is not always included in their binary distributions. This flag requires that
llvm-boltandmerge-fdataare available.BOLT is still a fairly new project so this flag should be considered experimental for now. Because this tool operates on machine code its success is dependent on a combination of the build environment + the other optimization configure args + the CPU architecture, and not all combinations are supported. BOLT versions before LLVM 16 are known to crash BOLT under some scenarios. Use of LLVM 16 or newer for BOLT optimization is strongly encouraged.
The
BOLT_INSTRUMENT_FLAGSandBOLT_APPLY_FLAGSconfigure variables can be defined to override the default set of arguments for llvm-bolt to instrument and apply BOLT data to binaries, respectively.Added in version 3.12.
- BOLT_APPLY_FLAGS¶
Arguments to
llvm-boltwhen creating a BOLT optimized binary.Added in version 3.12.
- BOLT_INSTRUMENT_FLAGS¶
Arguments to
llvm-boltwhen instrumenting binaries.Added in version 3.12.
- --with-computed-gotos¶
Enable computed gotos in evaluation loop (enabled by default on supported compilers).
- --with-tail-call-interp¶
Enable interpreters using tail calls in CPython. If enabled, enabling PGO (
--enable-optimizations) is highly recommended. This option specifically requires a C compiler with proper tail call support, and the preserve_none calling convention. For example, Clang 19 and newer supports this feature.Added in version 3.14.
- --without-mimalloc¶
Disable the fast mimalloc allocator (enabled by default).
See also
PYTHONMALLOCenvironment variable.
- --without-pymalloc¶
Disable the specialized Python memory allocator pymalloc (enabled by default).
See also
PYTHONMALLOCenvironment variable.
- --without-doc-strings¶
Disable static documentation strings to reduce the memory footprint (enabled by default). Documentation strings defined in Python are not affected.
Don’t define the
WITH_DOC_STRINGSmacro.See the
PyDoc_STRVAR()macro.
- --enable-profiling¶
Enable C-level code profiling with
gprof(disabled by default).
- --with-strict-overflow¶
Add
-fstrict-overflowto the C compiler flags (by default we add-fno-strict-overflowinstead).
- --without-remote-debug¶
Deactivate remote debugging support described in PEP 768 (enabled by default). When this flag is provided the code that allows the interpreter to schedule the execution of a Python file in a separate process as described in PEP 768 is not compiled. This includes both the functionality to schedule code to be executed and the functionality to receive code to be executed.
-
Py_REMOTE_DEBUG¶
This macro is defined by default, unless Python is configured with
--without-remote-debug.Note that even if the macro is defined, remote debugging may not be available (for example, on an incompatible platform).
Added in version 3.14.
-
Py_REMOTE_DEBUG¶
3.3.8. Python Debug Build¶
A debug build is Python built with the --with-pydebug configure
option.
Effects of a debug build:
Display all warnings by default: the list of default warning filters is empty in the
warningsmodule.Add
dtosys.abiflags.Add
sys.gettotalrefcount()function.Add
-X showrefcountcommand line option.Add
-dcommand line option andPYTHONDEBUGenvironment variable to debug the parser.Add support for the
__lltrace__variable: enable low-level tracing in the bytecode evaluation loop if the variable is defined.Install debug hooks on memory allocators to detect buffer overflow and other memory errors.
Define
Py_DEBUGandPy_REF_DEBUGmacros.Add runtime checks: code surrounded by
#ifdef Py_DEBUGand#endif. Enableassert(...)and_PyObject_ASSERT(...)assertions: don’t set theNDEBUGmacro (see also the--with-assertionsconfigure option). Main runtime checks:Add sanity checks on the function arguments.
Unicode and int objects are created with their memory filled with a pattern to detect usage of uninitialized objects.
Ensure that functions which can clear or replace the current exception are not called with an exception raised.
Check that deallocator functions don’t change the current exception.
The garbage collector (
gc.collect()function) runs some basic checks on objects consistency.The
Py_SAFE_DOWNCAST()macro checks for integer underflow and overflow when downcasting from wide types to narrow types.
See also the Python Development Mode and the
--with-trace-refs configure option.
Changed in version 3.8: Release builds and debug builds are now ABI compatible: defining the
Py_DEBUG macro no longer implies the Py_TRACE_REFS macro (see the
--with-trace-refs option).
3.3.9. Debug options¶
- --with-pydebug¶
Build Python in debug mode: define the
Py_DEBUGmacro (disabled by default).
- --with-trace-refs¶
Enable tracing references for debugging purpose (disabled by default).
Effects:
Define the
Py_TRACE_REFSmacro.Add
sys.getobjects()function.Add
PYTHONDUMPREFSenvironment variable.
The
PYTHONDUMPREFSenvironment variable can be used to dump objects and reference counts still alive at Python exit.Statically allocated objects are not traced.
Added in version 3.8.
Changed in version 3.13: This build is now ABI compatible with release build and debug build.
- --with-assertions¶
Build with C assertions enabled (default is no):
assert(...);and_PyObject_ASSERT(...);.If set, the
NDEBUGmacro is not defined in theOPTcompiler variable.See also the
--with-pydebugoption (debug build) which also enables assertions.Added in version 3.6.
- --with-valgrind¶
Enable Valgrind support (default is no).
- --with-dtrace¶
Enable DTrace support (default is no).
See Instrumenting CPython with DTrace and SystemTap.
Added in version 3.6.
- --with-address-sanitizer¶
Enable AddressSanitizer memory error detector,
asan(default is no). To improve ASan detection capabilities you may also want to combine this with--without-pymallocto disable the specialized small-object allocator whose allocations are not tracked by ASan.Added in version 3.6.
- --with-memory-sanitizer¶
Enable MemorySanitizer allocation error detector,
msan(default is no).Added in version 3.6.
- --with-undefined-behavior-sanitizer¶
Enable UndefinedBehaviorSanitizer undefined behaviour detector,
ubsan(default is no).Added in version 3.6.
- --with-thread-sanitizer¶
Enable ThreadSanitizer data race detector,
tsan(default is no).Added in version 3.13.
3.3.10. Linker options¶
Enable building a shared Python library:
libpython(default is no).
- --without-static-libpython¶
Do not build
libpythonMAJOR.MINOR.aand do not installpython.o(built and enabled by default).Added in version 3.10.
3.3.11. Libraries options¶
- --with-libs='lib1 ...'¶
Link against additional libraries (default is no).
- --with-system-expat¶
Build the
pyexpatmodule using an installedexpatlibrary (default is no).
- --with-system-libmpdec¶
Build the
_decimalextension module using an installedmpdecimallibrary, see thedecimalmodule (default is yes).Added in version 3.3.
Changed in version 3.13: Default to using the installed
mpdecimallibrary.Changed in version 3.15: A bundled copy of the library will no longer be selected implicitly if an installed
mpdecimallibrary is not found. In Python 3.15 only, it can still be selected explicitly using--with-system-libmpdec=noor--without-system-libmpdec.Deprecated since version 3.13, will be removed in version 3.16: A copy of the
mpdecimallibrary sources will no longer be distributed with Python 3.16.See also
- --with-readline=readline|editline¶
Designate a backend library for the
readlinemodule.readline: Use readline as the backend.
editline: Use editline as the backend.
Added in version 3.10.
- --without-readline¶
Don’t build the
readlinemodule (built by default).Don’t define the
HAVE_LIBREADLINEmacro.Added in version 3.10.
- --with-libm=STRING¶
Override
libmmath library to STRING (default is system-dependent).
- --with-libc=STRING¶
Override
libcC library to STRING (default is system-dependent).
- --with-openssl=DIR¶
Root of the OpenSSL directory.
Added in version 3.7.
- --with-openssl-rpath=[no|auto|DIR]¶
Set runtime library directory (rpath) for OpenSSL libraries:
no(default): don’t set rpath;auto: auto-detect rpath from--with-opensslandpkg-config;DIR: set an explicit rpath.
Added in version 3.10.
3.3.12. Security Options¶
- --with-hash-algorithm=[fnv|siphash13|siphash24]¶
Select hash algorithm for use in
Python/pyhash.c:siphash13(default);siphash24;fnv.
Added in version 3.4.
Added in version 3.11:
siphash13is added and it is the new default.
- --with-builtin-hashlib-hashes=md5,sha1,sha256,sha512,sha3,blake2¶
Built-in hash modules:
md5;sha1;sha256;sha512;sha3(with shake);blake2.
Added in version 3.9.
- --with-ssl-default-suites=[python|openssl|STRING]¶
Override the OpenSSL default cipher suites string:
python(default): use Python’s preferred selection;openssl: leave OpenSSL’s defaults untouched;STRING: use a custom string
See the
sslmodule.Added in version 3.7.
Changed in version 3.10: The settings
pythonand STRING also set TLS 1.2 as minimum protocol version.
- --disable-safety¶
Disable compiler options that are recommended by OpenSSF for security reasons with no performance overhead. If this option is not enabled, CPython will be built based on safety compiler options with no slow down. When this option is enabled, CPython will not be built with the compiler options listed below.
The following compiler options are disabled with
--disable-safety:-fstack-protector-strong: Enable run-time checks for stack-based buffer overflows.
-Wtrampolines: Enable warnings about trampolines that require executable stacks.
Added in version 3.14.
- --enable-slower-safety¶
Enable compiler options that are