I spent the last 3 hours trying to find out if it possible to disable or to build Python without the interactive mode or how can I get the size of the python executable smaller for linux.
As you can guess it's for an embedded device and after the cross compilation Python is approximately 1MB big and that is too much for me.
Now the questions:
Are there possibilities to shrink the Python executable? Maybe to disable the interactive mode (starting Python programms on the command line).
I looked for the configure options and tried some of them but it doesn't produce any change for my executable.
I compile it with optimized options from gcc and it's already stripped.
If you reallly want to shrink python, you can have a look at those project :
http://code.google.com/p/python-on-a-chip/
as said on the site :
Python-on-a-Chip (p14p) is a project to develop a reduced Python virtual machine (codenamed PyMite) that runs a significant subset of the Python language on microcontrollers without an OS. The other parts of p14p are the device drivers, high-level libraries and other tools. Please join the python-on-a-chip google group to discuss this project.
This may be a little lower level than expected, but it really is shrinked :
Features of the PyMite VM:
You could get interesting ideas from this project.
Beware that you only get the virtual machine, ie. you can run pyc files, not py. (pyc files are cross platform, though. And much smaller than py files)
In fact, if you really target smallest python, you need to disable parts of the library, but maybe also the compiler itself.
This site might have interesting pointers also : http://www.awaretek.com/pymo.html
There may be ways you can cram it down a little more just by configuring, but not much more.
Also, the actual interactive-mode code is pretty trivial, so I doubt you're going to save much there.
I'm sure there are more substantial features you're not using that you could hack out of the interpreter to get the size down. For example, you can probably throw out a big chunk of the parser and compiler and just deal with nothing but bytecode. The problem is that the only way to do that is to hack the interpreter source. (And it's not the most beautiful code in the world, so you're going to have to dedicate a good amount of time to learning your way around.) And you'll have to know what features you can actually hack out.
The only other real alternative would be to write a smaller interpreter for a Python-like language—e.g., by picking up the tinypy project. But from your comments, it doesn't sound as if "Python-like" is sufficient for you unless it's very close.
Well, I suppose there's one more alternative: Hack up a different, nicer Python implementation than CPython. The problem is that Jython and IronPython aren't native code (although maybe you can use a JVM->native compiler, or possibly cram enough of Jython into a J2ME JVM?), and PyPy really isn't ready for prime time on embedded systems. (Can you wait a couple years?) So, you're probably stuck with CPython.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With