Is there any way to make py2exe output .py
source files instead of byte-compiled .pyc
files in the library?
views:
101answers:
1I did it long ago, so I hope I remember correctly:
- Set compressed to False, so py2exe won't create a Zip'd library file.
- Set optimize to zero, so py2exe will write
pyc
files.
UPDATE: cool-RR
is right, use the skip_archive
option instead of compressed
.
You won't be able to modify your main Python file, since it will be embedded into the main executable, so keep that to a minimum. Then you'll be able to replace the pyc
files with your py
files manually in your distribution as needed. No reason to replace the standard libraries, however, only your own code.
(It is not optimal for debugging, but I guess you want to fix some problem happening only to the release build of your software this way.)
Please let me know if it does not work and I'll try to help.
UPDATE:
I've just read the relevant parts of the py2exe source code. It seems that py2exe does not support it out of the box. So we've left with the option to touch its source code.
You can easily modify py2exe
to support this mode. See the byte_compile
function in build_exe.py
. There's a call to the compile
built-in function in it, which you can replace with a copy_file
. Don't forget to modify the destination file name (dfile
) to have the extension .py
instead of .pyc
or .pyo
. I know that it is patchwork, but I don't see any other possibility to solve your problem.
You can also add a new py2exe
option or introduce a new optimize
value for this if you're curious. It would be an open-source contribution to py2exe, actually. ;)