简体   繁体   中英

Making py2exe produce `.py` files

有什么办法可以使py2exe输出.py源文件,而不是库中的字节编译.pyc文件?

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 : Ram Rachum 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. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM