Skip to content

zipapp exploded the python interpreter #4163

Description

@gfrankliu

We are using python 3.10 and the static python3 interpreter binary is about 45MB, but zipapp packs it three times so we end up with 150MB just for the interpreter alone, making the zipapp binary bloated.

$ ls -l runfiles/rules_python++python+python_3_10_x86_64-unknown-linux-gnu/bin/python*
-rwxrwxr-x 1 koi koi 44667000 Jan  1  1980 python
-rwxrwxr-x 1 koi koi 44667000 Jan  1  1980 python3
-rwxrwxr-x 1 koi koi     3149 Jan  1  1980 python3-config
-rwxrwxr-x 1 koi koi 44667000 Jan  1  1980 python3.10
-rwxrwxr-x 1 koi koi     3149 Jan  1  1980 python3.10-config

Also the static interpreter wouldn't need the shared libraries, but that is also being packed into zipapp, increase the size by another 45MB:

$ ls -l runfiles/rules_python++python+python_3_10_x86_64-unknown-linux-gnu/lib/
-rwxrwxr-x  1 koi koi 45131088 Jan  1  1980 libpython3.10.so.1.0
-rwxrwxr-x  1 koi koi    16800 Jan  1  1980 libpython3.so
-rwxrwxr-x  1 koi koi  2340016 Jan  1  1980 libtcl9.0.so
-rwxrwxr-x  1 koi koi  3082472 Jan  1  1980 libtcl9tk9.0.so
...

Activity

  1. aignas commented on Sep 17, 2026

    @aignas
    Collaborator

    So there are 2 root causes:

    Anything else to note here? I think the second bullet point is a new thing which should be scope of this ticket.

  2. gfrankliu commented on Sep 22, 2026

    @gfrankliu
    ContributorAuthor

    @aignas
    https://github.com/bazel-contrib/rules_python/blob/main/python/versions.bzl#L339
    Is there a reason why we didn't prefer the stripped python interpreter by default so we can have smaller size?
    It seems "install_only" Astral python-build-standalone package is being used by default, at least on linux x86_64, can we change to install_only_stripped ?

  3. added a commit that references this issue on Sep 27, 2026
    fd22cff
  4. added a commit that references this issue on Sep 27, 2026
    291e676
  5. rickeylev commented on Sep 28, 2026

    @rickeylev
    Collaborator

    Is there a reason why we didn't prefer the stripped python interpreter by default so we can have smaller size?

    I don't recall a particular reason. It's handy to have debugging symbols available by default when C code crashes. Do you want a build flag to pick the install flavor? I have a WIP change for that, but I put it on the backburner because I didn't see user requests for something like that and the size different didn't seem that big (relative to all the other stuff that gets downloaded when building a non-trivial python app).

  6. aignas commented on Sep 28, 2026

    @aignas
    Collaborator

    @aignas https://github.com/bazel-contrib/rules_python/blob/main/python/versions.bzl#L339 Is there a reason why we didn't prefer the stripped python interpreter by default so we can have smaller size? It seems "install_only" Astral python-build-standalone package is being used by default, at least on linux x86_64, can we change to install_only_stripped ?

    Reason is probably history - when the toolchains were added the binaries provided by the standalone python project were definitely different, but I can't remember if there were stripped symbols at the time.

    TBH, selecting strict vs non strict based on some debug flag would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions