API 和 ABI 版本控制

CPython exposes its version number in the following macros. Note that these correspond to the version code is built with, not necessarily the version used at run time .

C API 稳定性 for a discussion of API and ABI stability across versions.

PY_MAJOR_VERSION

3 in 3.4.1a2 .

PY_MINOR_VERSION

4 in 3.4.1a2 .

PY_MICRO_VERSION

1 in 3.4.1a2 .

PY_RELEASE_LEVEL

a in 3.4.1a2 . This can be 0xA 对于 Alpha, 0xB 对于 Beta, 0xC for release candidate or 0xF for final.

PY_RELEASE_SERIAL

2 in 3.4.1a2 . Zero for final releases.

PY_VERSION_HEX

The Python version number encoded in a single integer.

The underlying version information can be found by treating it as a 32 bit number in the following manner:

字节 位数 (大端在前次序) 含义

Value for 3.4.1a2

1 1-8 PY_MAJOR_VERSION 0x03
2 9-16 PY_MINOR_VERSION 0x04
3 17-24 PY_MICRO_VERSION 0x01

4

25-28 PY_RELEASE_LEVEL 0xA
29-32 PY_RELEASE_SERIAL 0x2

因此 3.4.1a2 是十六进制 0x030401a2 and 3.10.0 是十六进制 0x030a00f0 .

This version is also available via the symbol Py_Version .

const unsigned long Py_Version
属于 稳定 ABI (应用程序二进制接口) since version 3.11.

The Python runtime version number encoded in a single constant integer, with the same format as the PY_VERSION_HEX macro. This contains the Python version used at run time.

3.11 版新增。

所有给定宏的定义在 Include/patchlevel.h .

上一话题

支持循环垃圾收集

下一话题

分发 Python 模块

本页