Results 1 to 4 of 4

Thread: Compiling Python programs

  1. #1
    Join Date
    May 2006
    Location
    Netherlands
    Beans
    467

    Compiling Python programs

    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

  2. #2
    Join Date
    Apr 2006
    Location
    Sweden
    Beans
    Hidden!

    Re: Compiling Python programs

    Quote Originally Posted by EdThaSlayer View Post
    All I have been doing is running it via the interpeter.
    And that is how it is supposed to be run.

    You would only lose benefits for negliable speed increases, not worth the trouble.

    If you still feel like trying I suggest using Google.

  3. #3
    Join Date
    Oct 2006
    Location
    localhost
    Beans
    224

    Re: Compiling Python programs

    Quote Originally Posted by EdThaSlayer View Post
    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.
    See if these help...

    http://www.py2exe.org/
    http://effbot.org/zone/python-compile.htm
    http://www.devx.com/opensource/Article/20247
    Ubuntu User #9389 | Linux User #434733
    [Learn to Love the Penguin] [How to ask questions and not get flamed]

  4. #4
    Join Date
    Sep 2006
    Beans
    Hidden!

    Re: Compiling Python programs

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •