How about freezing zipimport into _bootstrap_python?

Currently, _bootstrap_python is used to freeze modules during python building. When running _bootstrap_python, stdlib files can be found in the source directory. However, when embedding cpython into another program, other build systems may be used to build cpython. Furthermore, these build systems may build cpython out of the source tree, even in a sandbox directory. Now, in order for the _bootstrap_python to function, we need to distribute the stdlib into the build directory. In this situation, a zip file of stdlib is the preferable way to do it. Unfortunately, the zipimport is not frozen into _bootstrap_python, so we can’t use a zip stdlib.

If we freeze zipimport into _bootstrap_python it will ease the build process a lot. It’s a very minor patch and we have tested it on Windows, Linux, and macOS. Admittedly, this change has no additional benefit to normal python building. But it doesn’t seem to be doing any harm. If this is OK, I’d like to create a PR for it.


P.S. the patch:

diff --git a/ b/
index 90f5dd7..9a328fc 100644
--- a/
+++ b/
@@ -976,7 +976,8 @@ Programs/_testembed: Programs/_testembed.o $(LINK_PYTHON_DEPS)

        Python/frozen_modules/importlib._bootstrap.h \
-       Python/frozen_modules/importlib._bootstrap_external.h
+       Python/frozen_modules/importlib._bootstrap_external.h \
+       Python/frozen_modules/zipimport.h

 Programs/_bootstrap_python.o: Programs/_bootstrap_python.c $(BOOTSTRAP_HEADERS) $(PYTHON_HEADERS)

diff --git a/Programs/_bootstrap_python.c b/Programs/_bootstrap_python.c
index bbac0c4..34f7919 100644
--- a/Programs/_bootstrap_python.c
+++ b/Programs/_bootstrap_python.c
@@ -12,6 +12,7 @@
 /* Includes for frozen modules: */
 #include "Python/frozen_modules/importlib._bootstrap.h"
 #include "Python/frozen_modules/importlib._bootstrap_external.h"
+#include "Python/frozen_modules/zipimport.h"
 /* End includes */

 /* Empty initializer for deepfrozen modules */
@@ -30,6 +31,7 @@ _Py_Deepfreeze_Fini(void)
 static const struct _frozen bootstrap_modules[] = {
     {"_frozen_importlib", _Py_M__importlib__bootstrap, (int)sizeof(_Py_M__importlib__bootstrap)},
     {"_frozen_importlib_external", _Py_M__importlib__bootstrap_external, (int)sizeof(_Py_M__importlib__bootstrap_external)},
+    {"zipimport", _Py_M__zipimport, (int)sizeof(_Py_M__zipimport)},
     {0, 0, 0} /* bootstrap sentinel */
 static const struct _frozen stdlib_modules[] = {

1 Like

I recommend that you use the issue tracker to submit this problem and add your solution as a PR.

Cool! I will create an issue on GitHub now. :smiley: