Python2 源码学习之 Windows 编译
1. 编译器准备
- 准备 Python 源码在 Python 的官网,下载需要进行编译的 Python 版本源代码。这里选择的是 Python 2 的最新版本
Python-2.7.14.tar.xz
,点击前往。 - 准备编译器在 Windows 上,Python 2.7 的源代码内置的项目工程,支持 Visual Studio 2008、2010 打开。当然,VS 2013 也能够编译,在导入项目时,选择升级 VC++编译器和库即可。这里使用的是,
VS2013_RTM_PRO_CHS
,点击下载。
2. 源代码的目录结构
- Demo:Demo 用的代码,主要用来展示 Python 的一些应用
- Doc:Python 的 UserManual,Latex 格式
- Grammar:语法文件。这个语法文件会在 Python 运行的时候被用来分析Python 源代码
- include:Python Include 用的头文件
- Lib:Python 的库文件
- Mac:For Mac
- Misc:如字面意思,一些不适合放在其他地方的文件就放在这里了
- Modules:Python 的一些 Built-in Module 的实现
- Objects:Python 的基本内部对象的实现,比如 class/list 等等
- Parser:Python 的词法分析和语法分析
- PC:比较老的 Windows 和 OS2 的 Port 的项目以及 Port 用到的一些公用文件放在这里,PCBuild 和 PCBuild8 都要用到这个目录的内容
- PCBuild:Python 用于 Visual Studio 2008/2010 的 Project 文件
- Python:Python 主程序代码
- RISCOS:Python 的 RISC OS Port
- Tools:Build 和 Extend Python 所需的工具
- 第二步,进入 PCbuild文件夹,使用 VS2013 打开 pcbuild.sln
- 第三步,编译运行。最终会在 PCbuild 文件夹下生成
python_d.exe
和python27_d.dll
文件,可双击python_d.exe
,进入 python 命令行环境。