#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    What is the command that will compile a python code to binary ?


    1) What is the command that will compile a python code to binary ?

    2) Is is true that a compiled Python code can be easily converted back to source code much easier than C code ?
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Windows - You need an application called py2exe.
    http://forums.devshed.com/t137769/s....ghlight=py2exe

    Linux - you could try cxFreeze

    Because python compiled code is stored in a form that is closer to the original script (bytecode) it is easier in theory to reverse engineer than the machine code generated by a C compiler. You can use a command line optimization -o to reduce the amount of human readable info stored in the bytecode to make the task harder.

    grim
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You can also use the -OO option on the command line to further reduce the chances though this results in docstrings being removed from your program which you might want to avoid

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    14
    It's not only easier in theory to reverse-engineer Python code, it's easier due to the fact that there exists a tool that can reliably do it. Google for "decompyle" for more info.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Smile reply


    Thank you everyone for your help.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Smile reply


    Hi netytan, thank you for your help.
    You said "You can also use the -OO option on the command line to further reduce the chances though this results in docstrings being removed from your program which you might want to avoid "

    Do you mean

    ./python_program -OO

    If not the above then please specify the exact command.
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Python command like arguments follow the interpreter, so something like this, assuming you have python in you PATH variable...

    python -OO program.py

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Smile reply


    Thank you netytan for your help.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Smile reply


    Hi again netytan.

    I ran the command below, but no binary file was created, and the file python_1.py remains as text.

    python -OO python_1.py
  18. #10
  19. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Please read Section 6.1.2 of the Python Tutorial that ships with Python. It explains the -O and -OO options.

    grim.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    Python source code ( my_prog.py ) is always text.

    When you run it through the interpreter (Python.exe) it converts the text to a "byte-code" that it can read. These end in .pyc - my_prog.pyc

    If you use python.exe -OO it will remove the comments from the byte-code file.

    Python.exe can not create Windows or Linux executable binaries though. For that you need a tool like py2exe which Grim_Archon linked to.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    Smile reply


    Thank you sfb for your help.

IMN logo majestic logo threadwatch logo seochat tools logo