最近,我必须为 64 位 Python 3.5.6 构建一个可嵌入的 zip(因为官方下载页面不提供高于 3.5.4 的 Python),以下是步骤。
先决条件(一次性安装)
Install
- git
- 乌龟SVN
- Visual Studio C++ Build Tools 2015 (you may need version 2017 when building latest Python versions)1
-
If you haven't Sphinx
installed, install it and add sphinx-build
to PATH
2:
> python -m pip install --user sphinx
> set PATH=%PATH%;C:\Users\jenkins\AppData\Roaming\Python\Python35\Scripts
-
如果你还没有blurb
已安装,安装,添加blurb
to PATH
如有必要(如果您已完成上一步,则您已经拥有正确的PATH
):
> python -m pip install --user blurb
> set PATH=%PATH%;C:\Users\jenkins\AppData\Roaming\Python\Python35\Scripts
配置构建环境
-
克隆 CPython 存储库。在这里,我仅克隆我需要的标签:
> git clone --depth 1 --branch v3.5.6 https://github.com/python/cpython
-
In the repo dir, generate NEWS
file3, 4:
> blurb merge -f Misc\NEWS
Build
现在您可以触发构建:
> Tools\msi\buildrelease.bat -x64 --skip-nuget --test testout
Replace -x64
with -x32
如果你的目标是 32 位架构。--skip-nuget
将省略构建 MSI 安装程序。--test testout
将触发安装程序测试;如果您愿意,可以跳过它们。
构建完成后,检查构建工件PCbuild\amd64\en-us\python-3.5.6-embed-amd64.zip
。这是您的可嵌入 zip。
第一次构建成功后,只要文档构建工件保留在存储库中,您就可以在未来的构建中跳过文档构建以进一步加速:
> Tools\msi\buildrelease.bat -x64 --skip-doc --skip-nuget --test testout
1 Make sure you select "Custom" in the VC++ Build Tools installer and check all the options; otherwise, you may get build errors like The code execution cannot proceed because ucrtbased.dll was not found
etc. I'm no Windows expert by all means, just installed everything possible to get rid of the errors.
2 Looking at the buildrelease.bat
help, it seems like you can skip the doc build with --skip-doc
flag, but when using that, I got the error
"C:\Users\jenkins\projects\cpython\Tools\msi\bundle\releaselocal.wixproj"
(Rebuild target) (1) ->
"C:\Users\jenkins\projects\cpython\Tools\msi\doc\doc.wixproj" (Rebuild target) (7) ->
(Link target) ->
C:\Users\jenkins\projects\cpython\Tools\msi\doc\doc_files.wxs(8): error
LGHT0103: The system cannot find the file 'python356.chm'. [C:\Users\jenkins\projects\cpython\Tools\msi\doc\doc.wixproj]
并且构建因错误而中止。如果您在没有初始文档构建的情况下设法规避此问题(因此文档文件在构建目录中可用),则可以跳过Sphinx
安装。
3 Otherwise, I get the build error
"C:\Users\jenkins\projects\cpython\Tools\msi\bundle\releaselocal.wixproj" (Rebuild target) (1) ->
"C:\Users\jenkins\projects\cpython\Tools\msi\exe\exe.wixproj" (Rebuild target) (8) ->
C:\Users\jenkins\projects\cpython\Tools\msi\exe\exe_files.wxs(9): error
LGHT0103: The system cannot find the file '!(bindpath.src)Misc\NEWS'. [C:\Users\jenkins\projects\cpython\Tools\msi\exe\exe.wixproj]
4 You can replace the command with an appropriate make
invocation, but I was too lazy to decipher the Doc\Makefile
. After all, the news won't land in the embeddable zip anyway; this is only to make the buildrelease.bat
happy.