Making executable binaries in Python (or Perl)
Archive - Originally posted on "The Horse's Mouth" - 2009-10-12 05:31:59 - Graham EllisIn a nutshell, translations of any of the scripting / semi-scripting languages into executables require the libraries that are included with the base distribution to be included with them, so they gain very little indeed in terms of efficiency or footprint; if the language uses dynamic memory allocation, it still needs that when compiled so you can't pull the application down to a fast and tiny single executable file, which is what most people who are asking this question are hoping for. Indeed, I spoke with the author of one of the major script to C converters and to paraphrase him, he wrote - "Graham - I wish I had never written that piece of code. It does exactly what was intended, but people assume it can do so much more that it's a support headache and I'm forever having to disappoint people"
A recent delegate writes ...
... I have discussed the possibility of migrating to Python for applications that we now developing, mostly in MATLAB. Being free resource Python is very attractive alternative to MATLAB. There was a question raised – is it possible to generate executable in Python? – based on Python source files? |
Although no easy "make me a small binary" exists, there is a close alternative in Python if you are looking to avoid the need to distribute your source. Place the whole application in a .py file (let's call in application.py) and run it via an enclosing script that simply states
from application import *
At the first run, this will generate a file application.oyc (or application .pyo - optimised - if you run it with the -O option which eliminates asserts and make some other optimisations) and you can then distribute / embed based purely on the binary files.