Creating py2exe creates `.py` files

Is there a way to make py2exe source files .py

instead of files compiled to bytes .pyc

in the library?

+2


a source to share


1 answer


I did this a long time ago, so I hope I remember correctly:

  • Set compression to False, so py2exe will not create a Zip'd library file.
  • Set optimization to zero, so py2exe will write files pyc

    .

UPDATE : Ram Rahum is right, use skip_archive

instead compressed

.

You won't be able to modify your main Python file as it will be embedded in the main executable, so keep it to a minimum. You can then replace the files with pyc

your files py

manually in your distribution as needed. There is no reason to replace the standard libraries, however, just your own code.

(This is not optimal for debugging, but I am assuming you want to fix some kind of problem only occurring with the build version of your software this way.)



Please let me know if this doesn't work and I'll try to help.

UPDATE

I just read the relevant parts of the py2exe source code. It seems that py2exe doesn't support it out of the box. Thus, we left the opportunity to touch the source code.

You can easily change py2exe

to support this mode. See Function byte_compile

in build_exe.py

. There is a call to a built-in function compile

that you can replace with copy_file

. Remember to change the destination file name ( dfile

) to have an extension .py

instead of .pyc

or .pyo

. I know this is a patchwork, but I see no other way to solve your problem.

You can also add a new option py2exe

or enter a new value optimize

for this if you're interested. It would actually be an open source contribution to py2exe.;)

+1


a source







All Articles