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. while running ” wine ~/.wine/drive_c/Python27/Scripts/pyinstaller.exe –onefile ” command I got error like this wine: cannot find ‘/home/mj/.wine/drive_c/Python27/Scripts/pyinstaller.exe’

    1. Hi kedar,
      i think that pyinstaller may not have been correctly installed , or installed in another directory.
      Have you tried to browse the ~/.wine/drive_c/Python27/Scripts/ directory in order to check the presence of pyinstaller.exe file?

  2. when i run the exe file in windows, it shows no module found “pygame”.
    so how can i cross compile code with packages?


This site uses Akismet to reduce spam. Learn how your comment data is processed.