Compiling Extension Modules on Windows using mingwΒΆ

  1. Python 2.5 (with earlier versions of Python, it is much more complicated to compile extensions with mingw. Use visual Studio 2003 if you cannot upgrade to Python 2.5)
  2. Local admin access on your machine
  1. Go to and go to the “downloads” section of the web-site. Look for the link to the sourceforge page and go there. Grab the latest version of the “Automated MinGW Installer” and run the installer.

  2. When asked “which MinGW package” you would like to install, select “Current” or “Candidate” depending on whether you want to be on the bleeding edge or not.

  3. When you get to the section where you need to select the various components you want to install, include the “base tools” and the “g++ compiler”, and possibly the g77 compiler too if you are going to be compiling some extensions that use Fortran.

  4. Install it to “C:” (the default location)

  5. Add “C:” to your PATH environment variable if the installer did not do this for you. If you are running Vista, you will need to add “C:32.4.5” to your PATH as well

  6. In notepad (or your favourite text editor) create a new text file and enter the following in the file:

    [build] compiler = mingw32

  7. Save the file as “C:25.cfg”. This will tell python to use the MinGW compiler when compiling extensions

  8. Close down any command prompts you have open (they need to be reopened to see the new environment variable values)

Note: this will only work for modules which have a script that uses distutils

  1. So lets say you have downloaded code for some module to the folder “xyz”. Open a command prompt and cd to this directory (eg. type “c:” then press enter to change to the C drive, then type “cd c:” to change to directory xyz)
  2. To create a binary installer, type “python bdist_wininst”
  3. If everything worked fine, then there should now be a subfolder called “dist” which contains an exe file that you can run to install the module.

Section author: MattKnox