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.
As mentioned by other answerers, the cross-compilation feature is removed from PyInstaller since
1.5
. Here, show how to package a Windows executable from Python scripts using PyInstaller under wine.Step 1: Install wine and Python
PS: Newer Python versions already include
pip
(is used to installpyinstaller
). Download Python installation package from here (e.g.,python-2.7.10.msi
)Step 2: Install PyInstaller on wine
Step 3: Package Python scripts
Package Python scripts (e.g.,
HelloWorld.py
) withpyinstaller
.The Windows executable file is located in
dist/
.Refer to here for the detailed description.
I have tested py2exe inside of wine, and it does function. You'll need to install python in wine for it to work, or if you only use the standard libarary, you can bundle py2exe with py2exe from the windows machine and then use it in wine. Just keep in mind you need the same version of the ms visual C libraries in wine as were used to compile python or things won't work properly.
You could run Windows in VirtualBox in order to run py2exe. VBox offers a powerful command-line client for automating tasks, so it something that you could likely integrate into your development process with ease.
Did you look at PyInstaller?
It seems that 1.4 support cross-compilation
http://www.pyinstaller.org/browser/tags/1.4/doc/CHANGES.txt says:
I didn't try it myself.
I hope it helps