I know quite a bit of Python, but now I wonder, is it possible to compile python programs? Like compile it into a ".bin" file? Then is there a program that can do that? All I have been doing is running it via the interpeter.
I know quite a bit of Python, but now I wonder, is it possible to compile python programs? Like compile it into a ".bin" file? Then is there a program that can do that? All I have been doing is running it via the interpeter.
Educate men without faith and you make them clever devils
Educate men without Linux, then yeah, the opposite happens
Let Chakra guide the way
U.3F
Ubuntu User #9389 | Linux User #434733
[Learn to Love the Penguin] [How to ask questions and not get flamed]
EdThaSlayer,
The only speed you would gain from compiling your scripts would be at load time; run time execution speed would be the same. Python byte-compiles scripts in memory, which is where the extra load time comes from. OTOH, modules you use in your scripts will be byte-compiled, and saved as *.pyc files. These will load faster than regular *.py files, as they are already byte-compiled. Python only recompiles these when the original *.py module has been changed.
The py2exe program that localuser pointed out above only works on Windows AFAIK. The final binary will be a lot larger than an equivalent Python script, because it basically combines your script, any modules it uses, and a Python interpreter into a single, stand-alone *.exe file.
What I would suggest doing if you are unsatisfied with the execution speed of your Python programs is to break your Python program down into modules. You could also look over these tips to glean possible benefits from optimizing your code. You might also be interested in psyco.
Bookmarks