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 ?
Windows - You need an application called 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.
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
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.
Thank you everyone for your help.
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
If not the above then please specify the exact command.
June 10th, 2004, 06:33 AM
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,
June 10th, 2004, 09:53 AM
Thank you netytan for your help.
June 10th, 2004, 09:58 AM
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
June 10th, 2004, 10:23 AM
Please read Section 6.1.2 of the Python Tutorial that ships with Python. It explains the -O and -OO options.
June 10th, 2004, 10:25 AM
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.
June 10th, 2004, 10:46 AM
Thank you sfb for your help.