Skip to content

Commit 0a87b70

Browse files
committed
完成Windows 环境下编译 Python
1 parent a6b610a commit 0a87b70

File tree

7 files changed

+33
-1
lines changed

7 files changed

+33
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ gitbook serve
5353
- [x] 序章
5454
- [x] 前言
5555
- [x] Python 源代码的组织
56-
- [ ] Windows 环境下编译 Python
56+
- [x] Windows 环境下编译 Python
5757
- [x] UNIX/Linux 环境下编译 Python
5858
- [x] 修改 Python 源码
5959
- [ ] Python 内建对象

preface/build-files.png

37.2 KB
Loading

preface/vs2017-build.png

183 KB
Loading

preface/vs2017-configure.png

193 KB
Loading

preface/vs2017-installation.png

422 KB
Loading

preface/vs2017-properties.png

129 KB
Loading

preface/windows-build.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# Windows 环境下编译 Python
22

3+
在 Windows 环境下编译 Python 可完全通过界面操作,主要分为两个步骤:
4+
5+
1. 环境准备
6+
2. 编译
7+
8+
## 环境准备
9+
10+
在 Python 3.6 及之后的版本可以使用微软的
11+
[Visual Studio 2017](https://visualstudio.microsoft.com/zh-hans/vs/) 进行编译,选择社区版就足够了。
12+
13+
在下载完成后,需要注意安装环节的选项。由于 Python 3.7 所使用的 Windows SDK 的版本为 `10.0.17134.0`
14+
所以需要选择安装该 SDK,如下图所示:
15+
![](vs2017-installation.png)
16+
17+
## 编译
18+
19+
进入 Python 源码根目录,打开 `PCbuild\pcbiuld.sln` 解决方案,而后进行一些设置:
20+
21+
在左侧的解决方案目录的顶端,右键选择“属性”,以打开属性界面(如下图所示)
22+
![](vs2017-properties.png)
23+
24+
由于我们只是研究 Python 的核心部分,可以选择不编译标准库和外部依赖,在“配置属性”->“配置”中仅勾选
25+
python 和 pythoncore,然后点击“确定”(如下图所示)。
26+
27+
此外,默认情况下的编译设置是 Debug、32 位,您也可以根据自己的需求调整成 Release 或 64 位。
28+
![](vs2017-configure.png)
29+
30+
在左侧的解决方案目录中选择 python,右键选择“生成”,以进行编译:
31+
![](vs2017-build.png)
32+
33+
编译结束后,生成的文件存放在`PCbuild\win32`目录下(如下图所示),打开`python_d`即可打开新生成的 Python 3.7 解释器。
34+
![](build-files.png)

0 commit comments

Comments
 (0)