blob: f855c633cfd5b886f0eb075543e1d524c4877fed [file] [log] [blame]
Victor Stinnera41782c2021-04-08 22:32:21 +02001****************
2Configure Python
3****************
4
5.. _configure-options:
6
7Configure Options
8=================
9
10List all ``./configure`` script options using::
11
12 ./configure --help
13
14See also the :file:`Misc/SpecialBuilds.txt` in the Python source distribution.
15
16General Options
17---------------
18
19.. cmdoption:: --enable-loadable-sqlite-extensions
20
21 Support loadable extensions in the :mod:`_sqlite` extension module (default
22 is no), see the :mod:`sqlite3` module.
23
24 .. versionadded:: 3.6
25
26.. cmdoption:: --disable-ipv6
27
28 Disable IPv6 support (enabled by default if supported), see the
29 :mod:`socket` module.
30
31.. cmdoption:: --enable-big-digits[=15|30]
32
33 Use big digits (15 or 30 bits) for Python :class:`int` numbers (default is
34 system-dependent).
35
36 See :data:`sys.int_info.bits_per_digit <sys.int_info>`.
37
38.. cmdoption:: --with-cxx-main[=COMPILER]
39
40 Compile the Python ``main()`` function and link Python executable with C++
41 compiler specified in *COMPILER* (default is ``$CXX``).
42
43.. cmdoption:: --with-suffix=SUFFIX
44
45 Set executable suffix to *SUFFIX* (default is ``.exe``).
46
47.. cmdoption:: --with-tzpath=<list of absolute paths separated by pathsep>
48
49 Select the default time zone search path for :data:`zoneinfo.TZPATH`,
50 see the :mod:`zoneinfo` module.
51
52 .. versionadded:: 3.9
53
54.. cmdoption:: --without-decimal-contextvar
55
56 Build the ``_decimal`` extension module using a thread-local context rather
57 than a coroutine-local context (default), see the :mod:`decimal` module.
58
59 See :data:`decimal.HAVE_CONTEXTVAR`.
60
61 .. versionadded:: 3.9
62
63.. cmdoption:: --with-dbmliborder=db1:db2:...
64
65 Override order to check db backends for the :mod:`dbm` module
66
67 A valid value is a colon separated string with the backend names:
68
69 * ``ndbm``;
70 * ``gdbm``;
71 * ``bdb``.
72
73.. cmdoption:: --with-c-locale-coercion
74
75 Enable C locale coercion to a UTF-8 based locale (default is yes).
76
77 See :envvar:`PYTHONCOERCECLOCALE` and the :pep:`538`.
78
79.. cmdoption:: --with-platlibdir=DIRNAME
80
81 Python library directory name (default is ``lib``).
82
83 Fedora and SuSE use ``lib64`` on 64-bit platforms.
84
85 See :data:`sys.platlibdir`.
86
87 .. versionadded:: 3.9
88
89.. cmdoption:: --with-wheel-pkg-dir=PATH
90
91 Directory of wheel packages used by the :mod:`ensurepip` module
92 (none by default).
93
94 Some Linux distribution packaging policies recommend against bundling
95 dependencies. For example, Fedora installs wheel packages in the
96 ``/usr/share/python-wheels/`` directory and don't install the
97 :mod:`ensurepip._bundled` package.
98
99 .. versionadded:: 3.10
100
101
102Install Options
103---------------
104
105.. cmdoption:: --disable-test-modules
106
107 Don't build nor install test modules, like the :mod:`test` package or the
108 :mod:`_testcapi` extension module (built and installed by default).
109
110 .. versionadded:: 3.10
111
112.. cmdoption:: --with-ensurepip[=install|upgrade|no]
113
114 ``install`` or ``upgrade`` using bundled pip of the :mod:`ensurepip` module,
115 when installing Python (default is ``upgrade``).
116
117 .. versionadded:: 3.6
118
119
120Performance options
121-------------------
122
123Configuring Python using ``--enable-optimizations --with-lto`` (PGO + LTO) is
124recommended for best performance.
125
126.. cmdoption:: --enable-optimizations
127
128 Enable Profile Guided Optimization (PGO) using :envvar:`PROFILE_TASK`
129 (disabled by default).
130
131 Disable also semantic interposition in libpython if ``--enable-shared`` and
132 GCC is used: add ``-fno-semantic-interposition`` to the compiler and linker
133 flags.
134
135 .. versionadded:: 3.6
136
137 .. versionchanged:: 3.10
138 Use ``-fno-semantic-interposition`` on GCC.
139
140.. envvar:: PROFILE_TASK
141
142 Environment variable used in the Makefile: Python command line arguments for
143 the PGO generation task.
144
145 Default: ``-m test --pgo --timeout=$(TESTTIMEOUT)``.
146
147 .. versionadded:: 3.8
148
149.. cmdoption:: --with-lto
150
151 Enable Link Time Optimization (LTO) in any build (disabled by default).
152
153 .. versionadded:: 3.6
154
155.. cmdoption:: --with-computed-gotos
156
157 Enable computed gotos in evaluation loop (enabled by default on supported
158 compilers).
159
160.. cmdoption:: --without-pymalloc
161
162 Disable the specialized Python memory allocator :ref:`pymalloc <pymalloc>`
163 (enabled by default).
164
165 See also :envvar:`PYTHONMALLOC` environment variable.
166
167.. cmdoption:: --without-doc-strings
168
169 Disable static documentation strings to reduce the memory footprint (enabled
170 by default). Documentation strings defined in Python are not affected.
171
172 If used, the ``WITH_DOC_STRINGS`` macro is not defined. See the
173 ``PyDoc_STRVAR()`` macro.
174
175.. cmdoption:: --enable-profiling
176
177 Enable C-level code profiling with ``gprof`` (disabled by default).
178
179
180.. _debug-build:
181
182Debug build
183-----------
184
185A debug build is Python built with the :option:`--with-pydebug` configure
186option.
187
188Effects of a debug build:
189
190* Define ``Py_DEBUG`` and ``Py_REF_DEBUG`` macros.
191* Add ``d`` to :data:`sys.abiflags`.
192* Add :func:`sys.gettotalrefcount` function.
193* Add :option:`-X showrefcount <-X>` command line option.
194* Add :envvar:`PYTHONTHREADDEBUG` environment variable.
195* The list of default warning filters is empty in the :mod:`warnings` module.
196* Install debug hooks on memory allocators to detect buffer overflow and other
197 memory errors: see :c:func:`PyMem_SetupDebugHooks`.
198* Build Python with assertions (don't set ``NDEBUG`` macro):
199 ``assert(...);`` and ``_PyObject_ASSERT(...);`` are removed.
200 See also the :option:`--with-assertions` configure option.
201* Add runtime checks, code surroundeded by ``#ifdef Py_DEBUG`` and ``#endif``.
202* Unicode and int objects are created with their memory filled with a pattern
203 to help detecting uninitialized bytes.
204* Many functions ensure that are not called with an exception raised, since
205 they can clear or replace the current exception.
206* The garbage collector (:func:`gc.collect` function) runs some quick checks on
207 consistency.
208* Add support for the ``__ltrace__`` variable: enable low-level tracing in the
209 bytecode evaluation loop if the variable is defined.
210
211See also the :ref:`Python Development Mode <devmode>` and the
212:option:`--with-trace-refs` configure option.
213
214.. versionchanged:: 3.8
215 Release builds and debug builds are now ABI compatible: defining the
216 ``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro, which
217 introduces the only ABI incompatibility.
218
219
220Debug options
221-------------
222
223.. cmdoption:: --with-pydebug
224
225 :ref:`Build Python in debug mode <debug-build>` (disabled by default).
226
227.. cmdoption:: --with-trace-refs
228
229 Enable tracing references for debugging purpose (disabled by default).
230
231 Effects:
232
233 * Define the ``Py_TRACE_REFS`` macro.
234 * Add :func:`sys.getobjects` function.
235 * Add :envvar:`PYTHONDUMPREFS` environment variable.
236
237 This build is not ABI compatible with release build (default build) or debug
238 build (``Py_DEBUG`` macro).
239
240 .. versionadded:: 3.8
241
242.. cmdoption:: --with-assertions
243
244 Build with C assertions enabled (default is no).
245
246 If set, the ``NDEBUG`` macro is not defined in the :envvar:`OPT` compiler
247 variable.
248
249 See also the :option:`--with-pydebug` option (:ref:`debug build
250 <debug-build>`) which also enables assertions.
251
252 .. versionadded:: 3.6
253
254.. cmdoption:: --with-valgrind
255
256 Enable Valgrind support (default is no).
257
258.. cmdoption:: --with-dtrace
259
260 Enable DTrace support (default is no).
261
262 .. versionadded:: 3.6
263
264.. cmdoption:: --with-address-sanitizer
265
266 Enable AddressSanitizer memory error detector, 'asan' (default is no).
267
268 .. versionadded:: 3.6
269
270.. cmdoption:: --with-memory-sanitizer
271
272 Enable MemorySanitizer allocation error detector, 'msan' (default is no).
273
274 .. versionadded:: 3.6
275
276.. cmdoption:: --with-undefined-behavior-sanitizer
277
278 Enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan'
279 (default is no).
280
281 .. versionadded:: 3.6
282
283
284Linker options
285--------------
286
287.. cmdoption:: --enable-shared
288
289 Enable building a shared Python library: "libpython" (default is no).
290
291.. cmdoption:: --without-static-libpython
292
293 Do not build ``libpythonMAJOR.MINOR.a`` and do not install ``python.o``
294 (built and enabled by default).
295
296 .. versionadded:: 3.10
297
298
299Libraries options
300-----------------
301
302.. cmdoption:: --with-libs='lib1 ...'
303
304 Link against additional libraries (default is no).
305
306.. cmdoption:: --with-system-expat
307
308 Build the :mod:`pyexpat` module using an installed ``expat`` library
309 (default is no).
310
311.. cmdoption:: --with-system-ffi
312
313 Build the :mod:`_ctypes` extension module using an installed ``ffi``
314 library, see the :mod:`ctypes` module (default is system-dependent).
315
316.. cmdoption:: --with-system-libmpdec
317
318 Build the ``_decimal`` extension module using an installed ``libmpdec``
319 library, see the :mod:`decimal` module (default is no).
320
321 .. versionadded:: 3.3
322
323.. cmdoption:: --with(out)-readline[=editline]
324
325 Use ``editline`` for backend or disable the :mod:`readline` module.
326
327 .. versionadded:: 3.10
328
329.. cmdoption:: --with-tcltk-includes='-I...'
330
331 Override search for Tcl and Tk include files.
332
333.. cmdoption:: --with-tcltk-libs='-L...'
334
335 Override search for Tcl and Tk libraries.
336
337.. cmdoption:: --with-libm=STRING
338
339 Override ``libm`` math library to *STRING* (default is system-dependent).
340
341.. cmdoption:: --with-libc=STRING
342
343 Override ``libc`` C library to *STRING* (default is system-dependent).
344
345.. cmdoption:: --with-openssl=DIR
346
347 Root of the OpenSSL directory.
348
349.. cmdoption:: --with-openssl-rpath=[DIR|auto|no]
350
351 Set runtime library directory (rpath) for OpenSSL libraries:
352
353 * ``no`` (default): don't set rpath;
354 * ``auto``: auto-detect rpath from :option:`--with-openssl` and
355 ``pkg-config``;
356 * *DIR*: set an explicit rpath.
357
358 .. versionadded:: 3.10
359
360
361Security Options
362----------------
363
364.. cmdoption:: --with-hash-algorithm=[fnv|siphash24]
365
366 Select hash algorithm for use in ``Python/pyhash.c``:
367
368 * ``fnv``;
369 * ``siphash24`` (default).
370
371 .. versionadded:: 3.4
372
373.. cmdoption:: --with-builtin-hashlib-hashes=md5,sha1,sha256,sha512,sha3,blake2
374
375 Built-in hash modules:
376
377 * ``md5``;
378 * ``sha1``;
379 * ``sha256``;
380 * ``sha512``;
381 * ``sha3`` (with shake);
382 * ``blake2``.
383
384 .. versionadded:: 3.9
385
386.. cmdoption:: --with-ssl-default-suites=[python|openssl|STRING]
387
388 Override the OpenSSL default cipher suites string:
389
390 * ``python``: use Python's preferred selection (default);
391 * ``openssl``: leave OpenSSL's defaults untouched;
392 * *STRING*: use a custom string, PROTOCOL_SSLv2 ignores the setting.
393
394 See the :mod:`ssl` module.
395
396 .. versionadded:: 3.7
397
398
399macOS Options
400-------------
401
402See ``Mac/README.rst``.
403
404.. cmdoption:: --enable-universalsdk[=SDKDIR]
405
406 Create a universal binary build. *SDKDIR* specifies which macOS SDK should
407 be used to perform the build (default is no).
408
409.. cmdoption:: --enable-framework[=INSTALLDIR]
410
411 Create a Python.framework rather than a traditional Unix install. Optional
412 *INSTALLDIR* specifies the installation path (default is no).
413
414.. cmdoption:: --with-universal-archs=ARCH
415
416 Specify the kind of universal binary that should be created. this option is
417 only valid when :option:`--enable-universalsdk` is set.
418
419 Options are:
420
421 * ``universal2``;
422 * ``32-bit``;
423 * ``64-bit``;
424 * ``3-way``;
425 * ``intel``;
426 * ``intel-32``;
427 * ``intel-64``;
428 * ``all``.
429
430.. cmdoption:: --with-framework-name=FRAMEWORK
431
432 Specify the name for the python framework on macOS only valid when
433 :option:`--enable-framework` is set (default: ``Python``).
434
435
436Compiler and linker flags
437=========================
438
439Options set by the ``./configure`` script, ``Makefile`` and by environment
440variables.
441
442Preprocessor flags
443------------------
444
445.. envvar:: CPP
446
447 C preprocessor.
448
449.. envvar:: CONFIGURE_CPPFLAGS
450
451 .. versionadded:: 3.6
452
453.. envvar:: CPPFLAGS
454
455 (Objective) C/C++ preprocessor flags, e.g. ``-I<include dir>`` if you have
456 headers in a nonstandard directory ``<include dir>``.
457
458 Both :envvar:`CPPFLAGS` and :envvar:`LDFLAGS` need to contain the shell's
459 value for setup.py to be able to build extension modules using the
460 directories specified in the environment variables.
461
462.. envvar:: BASECPPFLAGS
463
464 .. versionadded:: 3.4
465
466.. envvar:: MULTIARCH_CPPFLAGS
467
468 .. versionadded:: 3.6
469
470.. envvar:: PY_CPPFLAGS
471
472 Extra preprocessor flags added for building the interpreter object files.
473
474 Default: ``$(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)``.
475
476 .. versionadded:: 3.2
477
478Compiler flags
479--------------
480
481.. envvar:: CC
482
483 C compiler command.
484
485.. envvar:: CFLAGS
486
487 C compiler flags.
488
489.. envvar:: CFLAGS_NODIST
490
491 :envvar:`CFLAGS_NODIST` is used for building the interpreter and stdlib C
492 extensions. Use it when a compiler flag should *not* be part of the
493 distutils :envvar:`CFLAGS` once Python is installed (:issue:`21121`).
494
495 .. versionadded:: 3.5
496
497.. envvar:: EXTRA_CFLAGS
498
499 Extra C compiler flags.
500
501.. envvar:: CONFIGURE_CFLAGS
502
503 .. versionadded:: 3.2
504
505.. envvar:: CONFIGURE_CFLAGS_NODIST
506
507 .. versionadded:: 3.5
508
509.. envvar:: BASECFLAGS
510
511.. envvar:: OPT
512
513 Optimization flags.
514
515.. envvar:: CFLAGS_ALIASING
516
517 Strict or non-strict aliasing flags used to compile ``Python/dtoa.c``.
518
519 .. versionadded:: 3.7
520
521.. envvar:: CFLAGSFORSHARED
522
523 Extra C flags added for building the interpreter object files.
524
525.. envvar:: PY_CFLAGS
526
527 Default: ``$(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)``.
528
529.. envvar:: PY_CFLAGS_NODIST
530
531 Default: ``$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include/internal``.
532
533 .. versionadded:: 3.5
534
535.. envvar:: PY_STDMODULE_CFLAGS
536
537 C flags used for building the interpreter object files.
538
539 Default: ``$(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED)``.
540
541 .. versionadded:: 3.7
542
543.. envvar:: PY_CORE_CFLAGS
544
545 Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE``.
546
547 .. versionadded:: 3.2
548
549.. envvar:: PY_BUILTIN_MODULE_CFLAGS
550
551 Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN``.
552
553 .. versionadded:: 3.8
554
555
556Linker flags
557------------
558
559.. envvar:: CONFIGURE_LDFLAGS
560
561 Avoid assigning :envvar:`CFLAGS`, :envvar:`LDFLAGS`, etc. so users can use
562 them on the command line to append to these values without stomping the
563 pre-set values.
564
565 .. versionadded:: 3.2
566
567.. envvar:: LDFLAGS_NODIST
568
569 :envvar:`LDFLAGS_NODIST` is used in the same manner as
570 :envvar:`CFLAGS_NODIST`. Use it when a linker flag should *not* be part of
571 the distutils :envvar:`LDFLAGS` once Python is installed (:issue:`35257`).
572
573.. envvar:: CONFIGURE_LDFLAGS_NODIST
574
575 .. versionadded:: 3.8
576
577.. envvar:: LDFLAGS
578
579 Linker flags, e.g. ``-L<lib dir>`` if you have libraries in a nonstandard
580 directory ``<lib dir>``.
581
582 Both :envvar:`CPPFLAGS` and :envvar:`LDFLAGS` need to contain the shell's
583 value for setup.py to be able to build extension modules using the
584 directories specified in the environment variables.
585
586.. envvar:: LIBS
587
588 Libraries to pass to the linker, e.g. ``-l<library>``.
589
590.. envvar:: LDSHARED
591
592 Command to build a shared library.
593
594 Default: ``@LDSHARED@ $(PY_LDFLAGS)``.
595
596.. envvar:: BLDSHARED
597
598 Command to build libpython shared library.
599
600 Default: ``@BLDSHARED@ $(PY_CORE_LDFLAGS)``.
601
602.. envvar:: PY_LDFLAGS
603
604 Default: ``$(CONFIGURE_LDFLAGS) $(LDFLAGS)``.
605
606.. envvar:: PY_LDFLAGS_NODIST
607
608 Default: ``$(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST)``.
609
610 .. versionadded:: 3.8
611
612.. envvar:: PY_CORE_LDFLAGS
613
614 Linker flags used for building the interpreter object files.
615
616 .. versionadded:: 3.8