How to build a Windows installer under Linux or OSX

These are instructions for building a Windows installer (.exe) of your package under a foreign operating system. For this purposes, Wine is used to emulate Windows, although there is no reason why the extension cannot be built on a virtual machine.

  1. Install Wine (sudo apt-get install wine or available on OSX via macports).
  2. Install Python 2.7 from python.org.
  3. Install mingw. Click on the latest mingw-get-inst folder and download the exe file. Select the C, C++, and Fortran Compilers. You may get a log error when installing, but it should still work.
  4. Start the registry editor (wine regedit) and setup the system path:
  • Browse to the PATH key at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment, or use Edit > Find > PATH.
  • Append to it: c:\python27;c:\mingw\bin;c:\python27\scripts.
  • Right click and select New > String Value to create a new key called HOME and set it to c:\users\yourusername
  1. Create a new file in ~/.wine/dosdevices/c:/users/yourusername/ called pydistutils.cfg containing
[build]
compiler=mingw32

This tells distutils not to look for the Microsoft Compilers, but to use mingw as the default compiler.

  1. Get the setuptools-*.win32-py2.7.exe from http://pypi.python.org/pypi/setuptools and install.

7. Install Cython (using wine easy_install cython). Note: If you get error: unrecognized command line option '-mno-cygwin', remove the -mno-cygwin flags in the Mingw32CCompiler class in ~/.wine/dosdevices/c:/Python27/Lib/distutils/cygwinccompiler.py, then run easy_install again. For more information, see python issue 12641. The diff is as follows:

322,326c322,326
<         self.set_executables(compiler='gcc -O -Wall',
<                              compiler_so='gcc -mdll -O -Wall',
<                              compiler_cxx='g++ -O -Wall',
<                              linker_exe='gcc',
<                              linker_so='%s %s %s'
---
>         self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
>                              compiler_so='gcc -mno-cygwin -mdll -O -Wall',
>                              compiler_cxx='g++ -mno-cygwin -O -Wall',
>                              linker_exe='gcc -mno-cygwin',
>                              linker_so='%s -mno-cygwin %s %s'
  1. Optionally, install Numpy from provided installer. Browse to the desired numpy-*-win32-superpack-python27.exe.
  2. Compile your extension from within your package source directory
python setup.py bdist_wininst

This will only work if you have a setup.py file, similar to the one at https://github.com/stefanv/cython_demo.git.

This step should then generate a .exe in the dist/ directory.

BuildingWindowsInstaller (last edited 2012-12-23 22:02:01 by StevenSilvester)