这是 Python 版本 3.16.0 alpha 0
.. image:: https://github.com/python/cpython/actions/workflows/build.yml/badge.svg?branch=main&event=push :alt: CPython build status on GitHub Actions :target: https://github.com/python/cpython/actions
.. image:: https://dev.azure.com/python/cpython/_apis/build/status/Azure%20Pipelines%20CI?branchName=main :alt: CPython build status on Azure DevOps :target: https://dev.azure.com/python/cpython/_build/latest?definitionId=4&branchName=main
.. image:: https://img.shields.io/badge/discourse-join_chat-brightgreen.svg :alt: Python Discourse chat :target: https://discuss.python.org/
Copyright © 2001 Python Software Foundation. All rights reserved.
有关更多版权和许可信息,请参阅本文件末尾。
.. contents::
General Information
- Website: https://www.python.org
- Source code: https://github.com/python/cpython
- Issue tracker: https://github.com/python/cpython/issues
- Documentation: https://docs.python.org
- Developer's Guide: https://devguide.python.org/
Contributing to CPython
有关向 CPython 开发贡献的更完整说明,
请参阅 Developer Guide_。
.. _Developer Guide: https://devguide.python.org/
Using Python
可安装的 Python 套件以及有关使用 Python 的信息,可在
python.org_ 上获取。
.. _python.org: https://www.python.org/
Build Instructions
在 Unix、Linux、BSD、macOS 和 Cygwin 上::
./configure
make
make test
sudo make install
这将把 Python 安装为 python3。
你可以向 configure 脚本传递许多选项;运行 ./configure --help
以了解更多信息。 在 macOS 的大小写不敏感文件系统以及 Cygwin 上,
可执行文件名为 python.exe; elsewhere it's just python。
构建完整的 Python 安装需要使用各种
额外的第三方库,具体取决于你的构建平台和
configure 选项。 并非所有标准库模块都能在所有平台上
构建或使用。 请参阅
Install dependencies <https://devguide.python.org/getting-started/setup-building.html#build-dependencies>_
部分,以获取关于各种 Linux 发行版和 macOS 依赖项的
Developer Guide_ 中的当前详细信息。
在 macOS 上,存在与 macOS 框架和通用构建相关的
额外 configure 和构建选项。 请参阅 Mac/README.rst <https://github.com/python/cpython/blob/main/Mac/README.rst>_。
在 Windows 上,请参阅 PCbuild/readme.txt <https://github.com/python/cpython/blob/main/PCbuild/readme.txt>_。
要构建 Windows 软件包,请参阅 PC/layout/README.md <https://github.com/python/cpython/blob/main/PC/layout/README.md>_。
如果你愿意,可以创建一个子目录并从那里调用 configure。 例如::
mkdir debug
cd debug
../configure --with-pydebug
make
make test
(如果你也在顶层目录进行了构建,这将失败。 你应该先
在顶层目录执行 make clean。)
要获取 Python 的优化构建,请在运行 make 之前
执行 configure --enable-optimizations。 这将设置默认的 make 目标以启用
基于剖析的优化 (PGO),并可能用于在某些平台上自动启用
链接时优化 (LTO)。 有关更多详细信息,请参阅
以下部分。
基于剖析的优化 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
PGO 利用了 GCC 或 Clang 编译器的近期版本。 如果使用,
无论是通过 configure --enable-optimizations 还是手动运行
make profile-opt,无论 configure 标志如何,优化后的构建
过程将执行以下步骤:
整个 Python 目录会被清理掉可能由先前编译产生的临时文件。
使用每种变体合适的编译器标志,构建一个插桩版本的解释器。 请注意,这只是一个中间步骤。 该步骤产生的 二进制文件不适合实际工作负载,因为它内部嵌入了剖析指令。
在插桩解释器构建完成后,Makefile 将运行一个训练 工作负载。 这是为了剖析解释器的执行所必需的。 请注意,在此步骤中可能出现的任何输出,包括 stdout 和 stderr, 都会被抑制。
最后一步是构建实际的解释器,使用从插桩版本中 收集的信息。 最终结果将是一个经过优化的 Python 二进制文件, 适合分发或生产环境安装。
链接时优化 ^^^^^^^^^^^^^^^^^^^^^^
通过 configure 的 --with-lto 标志启用。 LTO 利用了
近期编译器工具链在构建最终可执行文件或共享
库时,跨越通常任意的 .o 文件边界进行优化的能力,以获得额外的性能提升。
What's New
我们在 What's new in Python 3.16 <https://docs.python.org/3.16/whatsnew/3.16.html>_ 文档中提供了全面的变更概览。 如需更详细的
变更日志,请阅读 Misc/NEWS <https://github.com/python/cpython/tree/main/Misc/NEWS.d>,但完整的
变更详情只能从 commit history <https://github.com/python/cpython/commits/main> 中获取。
如果您想安装多个版本的 Python,请参阅下方 标题为“Installing multiple versions”的章节。
Documentation
Documentation for Python 3.16 <https://docs.python.org/3.16/>_ 已在线发布,
每日更新。
它也可以下载为多种格式以便快速访问。 文档 可下载为 HTML、EPUB 和 reStructuredText 格式;后者主要面向 文档作者、翻译人员以及有特殊 格式要求的人员。
有关构建 Python 文档的信息,请参阅 Doc/README.rst <https://github.com/python/cpython/blob/main/Doc/README.rst>_。
Testing
要测试解释器,请在顶层目录中输入 make test。
测试集会产生一些输出。 通常可以忽略关于
因无法导入的可选功能而跳过测试的消息。 如果打印了
关于测试失败的消息,或者产生了 traceback 或 core dump,
则说明存在问题。
默认情况下,测试被限制以过度使用磁盘空间和
内存等资源。 要启用这些测试,请运行 make buildbottest。
如果任何测试失败,您可以以详细模式重新运行失败的测试。 例如,如果 test_os and test_gdb 失败,您可以运行::
make test TESTOPTS="-v test_os test_gdb"
如果故障持续存在,并且看起来是 Python 本身的问题,而不是
你的环境问题,你可以 file a bug report <https://github.com/python/cpython/issues>_ 并包含该命令的相关输出以展示该问题。
有关运行测试的更多信息,请参阅 Running & Writing Tests <https://devguide.python.org/testing/run-write-tests.html>_。
安装多个版本
在 Unix 和 Mac 系统上,如果你打算使用相同的安装前缀(--prefix 参数传递给 configure
脚本)来安装多个版本的 Python,你必须注意确保你的主要 python 可执行文件不会
被不同版本的安装所覆盖。 所有使用 make altinstall 安装的文件和
目录都包含主版本号和次版本号,因此可以并排存在。 make install 还会创建
${prefix}/bin/python3 which refers to ${prefix}/bin/python3.X。 如果你
打算使用相同的前缀安装多个版本,你必须决定哪个
版本(如果有)是你的“主要”版本。 使用
make install. Install all other versions using make altinstall 安装该版本。
例如,如果你想安装 Python 2.7、3.6 和 3.15,并且 3.15 是
主要版本,你会在 3.15 构建目录中执行 make install,
并在其他目录中执行 make altinstall。
发布计划
有关 Python 3.16 的发布详情,请参阅 PEP 826 <https://peps.python.org/pep-0826/>__。
版权和许可信息
Copyright © 2001 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2001 Corporation for National Research Initiatives. All rights reserved.
版权所有 © 1991-1995 Stichting Mathematisch Centrum。 保留所有权利。
请参阅 LICENSE <https://github.com/python/cpython/blob/main/LICENSE>_ 以获取
有关此软件的历史、使用条款和条件以及
所有保证的免责声明的信息。
此 Python 发行版不包含任何 GNU 通用公共许可证 (GPL) 代码, 因此可用于专有项目。 存在一些到某些 GNU 代码的接口,但这些完全是可选的。
此处提及的所有商标均为其各自持有者的财产。