Search code examples
pythonlinuxwindowspy2exe

Packaging a Python script on Linux into a Windows executable


I have a Python script that I'd like to compile into a Windows executable. Now, py2exe works fine from Windows, but I'd like to be able to run this from Linux. I do have Windows on my development machine, but Linux is my primary dev platform and I'm getting kind of sick of rebooting into Windows just to create the .exe. Nor do I want to have to buy a second Windows license to run in a virtual machine such as VirtualBox. Any ideas?

PS: I am aware that py2exe doesn't exactly compile the python file as much as package your script with the Python interpreter. But either way, the result is that you don't need Python installed to run the script.


Solution

  • Did you look at PyInstaller?

    It seems that versions through 1.4 support cross-compilation (support was removed in 1.5+). See this answer for how to do it with PyInstaller 1.5+ under Wine.

    Documentation says:

    Add support for cross-compilation: PyInstaller is now able to build Windows executables when running under Linux. See documentation for more details.

    I didn't try it myself.

    I hope it helps