3. 配置 Python¶
3.1. 建置需求¶
要建置 CPython,你將需要:
一個 C11 編譯器。選擇性 C11 功能並非必要。
在 Windows 上需要 Microsoft Visual Studio 2017 或更新版本。
支援 IEEE 754 浮點數與浮點數非數值 (NaN)。
thread 的支援。
在 3.5 版的變更: 在 Windows 上現在需要 Visual Studio 2015 或更新版本。
在 3.6 版的變更: Selected C99 features, like <stdint.h> and static inline functions,
are now required.
在 3.7 版的變更: 執行緒支援現在是必要的。
在 3.11 版的變更: 現在需要 C11 編譯器、IEEE 754 和 NaN 支援。在 Windows 上需要 Visual Studio 2017 或更新版本。
See also PEP 7 "Style Guide for C Code" and PEP 11 "CPython platform support".
3.1.1. 可選模組的需求¶
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.
建置可選模組的依賴項目為:
Dependency |
Minimum version |
Python 模組 |
|---|---|---|
建議使用 3.3.0 版本 |
||
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.
也參考
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.
在 3.1 版的變更: tkinter 現在需要 Tcl/Tk version 8.3.1。
在 3.5 版的變更: tkinter 現在需要 Tcl/Tk version 8.4。
在 3.11 版的變更: tkinter 現在需要 Tcl/Tk version 8.5.12。
在 3.13 版的變更: sqlite3 現在會需要 SQLite 3.15.2。
3.2. 產生的檔案¶
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. 設定腳本¶
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.
在 3.13 版的變更: Autoconf 2.71 and aclocal 1.16.5 and are now used to regenerate
configure.
在 3.14 版的變更: 現在使用 Autoconf 2.72 來重新產生 configure。
3.3. 設定選項¶
使用以下命令列出所有 configure 腳本選項:
./configure --help
請見 Python 原始碼發行版中的 Misc/SpecialBuilds.txt。
3.3.1. 一般選項¶
- --enable-loadable-sqlite-extensions¶
Support loadable extensions in the
_sqliteextension module (default is no) of thesqlite3module.請見
sqlite3模組的sqlite3.Connection.enable_load_extension()方法。在 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.
將
PYLONG_BITS_IN_DIGIT定義為15或30。
- --with-suffix=SUFFIX¶
將 Python 執行檔的後綴設定為 SUFFIX。
在 Windows 和 macOS 上預設的後綴是
.exe(python.exe執行檔)、在 Emscripten node 上為.js、在 Emscripten 瀏覽器為.html、在 WASI 上為.wasm,以及在其他平台為空字串(python執行檔)。在 3.11 版的變更: 在 WASM 平台上預設的後綴是
.js、.html或.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.預設值:
/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo。請見
os.pathsep路徑分隔符號。在 3.9 版被加入.
- --without-decimal-contextvar¶
Build the
_decimalextension module using a thread-local context rather than a coroutine-local context (default), see thedecimalmodule.請見
decimal.HAVE_CONTEXTVAR與contextvars模組。在 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).
不要定義
PY_COERCE_C_LOCALE巨集。請見
PYTHONCOERCECLOCALE與 PEP 538。
- --with-platlibdir=DIRNAME¶
Python 函式庫目錄名稱(預設為
lib)。Fedora 和 SuSE 在 64 位元平台上使用
lib64。參閱
sys.platlibdir。在 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.在 3.10 版被加入.
- --with-pkg-config=[check|yes|no]¶
Whether configure should use pkg-config to detect build dependencies.
check(預設):pkg-config 是可選的yes:pkg-config 是必要的no:即使存在也不使用 pkg-config 來配置
在 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.