indygreg / python-build-standalone

Produce redistributable builds of Python
BSD 3-Clause "New" or "Revised" License
1.71k stars 107 forks source link

Questions about libpython size, specifically on Linux x86_64 #275

Open ceejatec opened 1 week ago

ceejatec commented 1 week ago

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.

jfcherng commented 5 days ago
  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. 😄

bulletmark commented 5 days ago

See also related discussion here.

jfcherng commented 5 days ago

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?

bulletmark commented 5 days ago

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