Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build embeddable Python

I am wondering how to build embeddable Python for Windows. Could not find any info or build configuration for that particular package.

Reason I ask is that I could use the same variant for Mac and Linux.

like image 411
abergmeier Avatar asked Feb 16 '17 17:02

abergmeier


1 Answers

Recently, I had to build an embeddable zip for 64bit Python 3.5.6 (since the official download page doesn't offer them for Python greater than 3.5.4), here are the steps.

Prerequisites (one-time install)

Install

  1. git
  2. TortoiseSVN
  3. Visual Studio C++ Build Tools 2015 (you may need version 2017 when building latest Python versions)1
  4. If you haven't Sphinx installed, install it and add sphinx-build to PATH2:

    > python -m pip install --user sphinx
    > set PATH=%PATH%;C:\Users\jenkins\AppData\Roaming\Python\Python35\Scripts
    
  5. If you haven't blurb installed, install it, add blurb to PATH if necessary (if you've done the previous step, you already have the correct PATH):

    > python -m pip install --user blurb
    > set PATH=%PATH%;C:\Users\jenkins\AppData\Roaming\Python\Python35\Scripts
    

Configure build environment

  1. Clone CPython repo. Here, I clone only the tag I need:

    > git clone --depth 1 --branch v3.5.6 https://github.com/python/cpython
    
  2. In the repo dir, generate NEWS file3, 4:

    > blurb merge -f Misc\NEWS
    

Build

Now you can trigger the build:

> Tools\msi\buildrelease.bat -x64 --skip-nuget --test testout

Replace -x64 with -x32 if you target the 32bit arch. --skip-nuget will omit building the MSI installer. --test testout will trigger installer tests; you can skip them if you want.

Once the build finishes, check for build artifact PCbuild\amd64\en-us\python-3.5.6-embed-amd64.zip. This is your embeddable zip.

After the build succeeds for the first time, you can skip the doc build in future builds for further speedup as long as the doc build artifacts remain in repo:

> 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]

and the build aborts with an error. If you manage to circumvent this without an initial doc build (so the doc files are available in the build dir), you can skip Sphinx install.

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.

like image 196
hoefling Avatar answered Oct 03 '22 22:10

hoefling