2

We make an ARM 9 embedded system, Linux, etc. Recently a customer asked we pre-install Python 3 for them. We worked out the cross-compile (QEMU is really magical), but the resultant build is 177Mb, so that's a no go. What's the best plan here - we can leave off the Doc directory, and maybe the "build" dir? I see the Lib directory is 54Mb - is it a case of picking an choosing what libs the customer needs? We know very little about Python. To be clear, I see lots of advice about packaging Python apps - that's not what we are doing - we are packaging the Python runtime. Thanks! (directory size summary below)

1.6M  ./Python-3.6.0/Mac
760K  ./Python-3.6.0/Include
17M   ./Python-3.6.0/build
5.4M  ./Python-3.6.0/Python
8.0K  ./Python-3.6.0/.github
54M   ./Python-3.6.0/Lib
2.7M  ./Python-3.6.0/PC
2.7M  ./Python-3.6.0/Tools
6.9M  ./Python-3.6.0/Objects
11M   ./Python-3.6.0/Doc
824K  ./Python-3.6.0/Parser
20M   ./Python-3.6.0/Modules
15M   ./Python-3.6.0/Programs
620K  ./Python-3.6.0/PCbuild
12K   ./Python-3.6.0/Grammar
5.8M  ./Python-3.6.0/Misc
161M  ./Python-3.6.0
177M  .
Jeff
  • 1,969
  • 3
  • 21
  • 35
  • See Alex Martelli's answer to this question: http://stackoverflow.com/questions/2344712/minimize-python-distribution-size – D Krueger Feb 14 '17 at 22:48
  • Thanks - I've seen answers like that - but makes the runtime specific to a particular python application, right? That's not what I want - I'd like to know the most "common" way to distribute Python in general, not for one specific application. – Jeff Feb 15 '17 at 06:16

2 Answers2

0

A possible choice to meet your requirements may be MicroPython which is an implementation of PYthon 3 which consists of a small subset of the Python standard library. According to their website it is targeted for micro controllers and constrained environments: https://micropython.org/

According to their description MicroPython aims to be as compatible with normal Python as possible to allow you to transfer code with ease from the desktop to a microcontroller or embedded system. Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM.

There is an online project that puts an implementation of MicroPyton in an Arm Cortex M4 based embeeded system may also prove helpful: https://github.com/micropython/micropython/wiki

Dave S
  • 973
  • 9
  • 17
0

We removed the following:

  1. python3-tests
  2. libpython3.8-staticdev
  3. python3-*src
  4. python3-*dbg
  5. python3-*dev
  6. All the .pyc files (they can be recompiled after install)

We chose not to go ahead with the following:

  1. Removing "unneeded" modules: may break the dependencies of 3rd party libraries
  2. UPX binary packer: the zipped installation media is the same size, so this only slows down startup
  3. python source file minification: produced broken code, as we found out when regenerating the .pyc with python3 -m compileall .
Dan
  • 875
  • 1
  • 10
  • 11