# 四、编译 CPython

在下载并配置好了 CPython 开发环境后，现在你可以将 CPython 源码编译为可执行的解释器了。

与 Python 文件不同，C 源码每次修改后都必须被重新编译。这些编译操作你将来会多次重复，因此你可能需要标记本章并记住其中的一些步骤。

在第 3 章中，你了解了如何准备开发环境，其中包含了用来重新编译 CPython 的 “Build” 选项。为了完成构建工作，你需要一个 C 编译器和一些构建工具。

使用的工具取决于你使用的操作系统，因此你可以直接阅读适用于你的操作系统的章节。

{% hint style="info" %}
**注**

CPython 的源目录类似于一个虚拟环境。因此你不用担心这其中的任何一个步骤会干扰你安装的其他 CPython。

编译 CPython、修改源代码和标准库的这些操作都发生在源目录的沙箱中。

本章也涵盖了安装自定义版本的相关内容。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hai-shi.gitbook.io/cpython-internals/4-compiling-cpython.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
