tags:

views:

101

answers:

1

Is there any way to make py2exe output .py source files instead of byte-compiled .pyc files in the library?

A: 

I 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. ;)

fviktor
I'm already able to manually replace them with py files. (Also, I'm doing `skip_archive` to have a folder instead of a zip file.)I just wish py2exe won't try to be that smart; I wish it'll just copy the original package contents for each package into the library. Asides from it compiling the `.py` files, it also misses some data files for some scientific packages for example.
cool-RR
You can list the data files missed by `py2exe` explicitly in the `data_files` option. See also: http://py2exe.org/index.cgi/data_files
fviktor
Please see my update above. I hope it helps.
fviktor