Skip to content

Questions about libpython size, specifically on Linux x86_64 #275

Open

Description

@ceejatec

Several possibly-related questions. Note that I'm not necessarily saying anything is "wrong" here, I'm just trying to understand the differences.

So I've noticed two things about libpython.3.xx.so.1.0, working on x86_64-unknown-linux-gnu:

  1. Python 3.12's libpython is 4x the size of Python 3.11: 212MB vs. 58MB. If you strip both of them, the size difference largely vanishes; Python 3.12 is 25.3MB, where Python 3.11 is 24.4MB.
  2. python-build-standalone's stripped libpython is still something like 4x larger than the libpython that comes with Fedora 40, which is 6.1MB for Python 3.12 and 4.9MB for Python 3.11.

This is particularly noticeable when developing standalone binaries with PyInstaller. I've hacked PyInstaller locally to work with python-build-standalone, but the resulting binaries are nearly 3x the size compared to building with Fedora's python even if I build with the stripped libpython, which is kind of rough.

Activity

  1. jfcherng commented on Jun 28, 2024

    @jfcherng
    1. Python 3.12's libpython is 4x the size of Python 3.11: 212MB vs. 58MB. If you strip both of them, the size difference largely vanishes; Python 3.12 is 25.3MB, where Python 3.11 is 24.4MB.

    Thanks for this information. I was wondering why my PyInstaller-packaged APP became much larger. 😄

  2. bulletmark commented on Jun 28, 2024

    @bulletmark

    See also related discussion here.

  3. jfcherng commented on Jun 28, 2024

    @jfcherng

    See also related discussion here.

    Thanks for this information. I do have a script for installation so I can add a strip step during installing. Currently I just use strip without any CLI flags. Do you have recommended flags?

  4. bulletmark commented on Jun 28, 2024

    @bulletmark

    My installer uses strip -p --strip-unneeded.

  5. indygreg commented on Jul 13, 2024

    @indygreg
    Collaborator

    I wonder if the debug symbols size has something to do with BOLT, which is 3.12+ only. Maybe BOLT is producing sub-optimal DWARF records, not preserving compression in symbols, or something along those lines.

  6. charliermarsh commented on Jul 14, 2024

    @charliermarsh
    Member

    FWIW on macOS, I only see a ~12% reduction in libpython3.10.dylib size.

  7. TheExDeus commented on May 23, 2025

    @TheExDeus

    I also see that if I install python using UV, the sizes are quite a bit bigger than if I use python slim in docker.
    Note that the libpython3.13.so is almost 6x larger in UV (python-build-standalone) than in slim. I don't have an option in UV to install the stripped version maybe? If so I will make an issue there. But it also seems that this packs tcl, tk and some other things which I guess are optional as they aren't packed in -slim. So could we make a minimized python standalone for docker case? I know that it will be larger than python:x-slim base images, but I'm fine with that, because using UV is very convenient and universal when using different base images. But currently the difference in size is 78.1MB (slim) vs 120MB (ubuntu24+python-by-uv), so almost a third. Would be good to get closer, and it seems we could get there if .so's where similar size.

    Image

  8. johnthagen commented on Aug 11, 2025

    @johnthagen

    Some Pyinstaller comments upstream that might be relevant

    ... and the bloat factor due to PyInstaller being unable to drop large unneeded extension modules.

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

    performancePotential performance improvement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions