How to cross-compile a Python script into a Windows executable on Linux

Using Wine and Pyinstaller.

Pyinstaller is a program that packages Python programs into stand-alone executables, under the most used OSs (Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX).
Initially Pyinstaller had a beta feature that allows the cross-compilation of a windows executable under Linux.
However, due the instability of the feature, it has been removed since version 1.5.

Fortunately, is still possible to package a Windows executable using PyInstaller under Wine.

1. Install wine and Python

$ sudo apt-get install wine
$ wget
$ wine msiexec /i python-2.7.9.amd64.msi /qb

If you need to compile a 32bit executable, you need to install wine32:

sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install wine32

2. Install PyInstaller on wine

$ cd ~/.wine/drive_c/Python27
$ wine python.exe Scripts/pip.exe install pyinstaller

3. Package a python scripts

Package Python scripts (e.g., with pyinstaller.

$ cat
#!/usr/bin/env python
print('Hello World!')

$ wine ~/.wine/drive_c/Python27/Scripts/pyinstaller.exe --onefile

The Windows executable file is located in dist/.

$ wine dist/helloworld.exe
Hello World!

Finally, transfer the executable on a windows box and test it:


Related posts

  1. Cybersecurity Roundup #15
  2. Why Huawei USB stick setup on linux adds a strange “Huawei Autorun” script in system start?
  3. pySchö: algorithmic music composition
  4. LinuxCheck: Linux information gathering tool
  5. Quick mount of iOS Apps documents on Linux, using iFuse and bash