From: Jimmy Retzlaff <jimmy@re...> - 2006-04-02 15:01:37
Zach Hensel wrote:
> I recently compiled some image analysis scripts in Python and used
> py2exe to let me run them on computers without Python installed,
> bundling everything into a single executable. Of course someone came
> into my house and stole the computer I was using to develop the code
> with, and of course my data backup strategy wasn't particularly
> rigorous. Is there any best way to back the script out of a py2exe
> file, if anything would work at all?
Ouch. Good and bad news... it is possible, but not necessarily easy...
- First you'd need to extract your main script (the one you included in
the windows or console parameter to py2exe) from a binary resource in
the exe. It won't be the text of your source file, but rather byte-codes
- the result of a call to Python's built-in compile function.
- Second you need to trim the executable down to the point where it is a
valid zip file. That zip file contains pyc/pyo files for all the Python
in your app other than your main script (again they aren't plain text
- Finally you need to decompile the byte-code for the main script and
the pyc/pyo files. There used to be something called decompyle that did
a marvelous job of this for pyc/pyo files, but the last time I paid
attention it didn't support versions of Python past 2.2. There might be
something newer, but I don't know about it (I haven't really been paying
attention to that sort of thing).
You'll have to evaluate whether your code is easier to recreate from the
exe or from your memory. I can give you a few more details about the
first 2 bullets if you find a solution you're happy with for the 3rd.
Get latest updates about Open Source Projects, Conferences and News.