Home Up

How to create a Windows Binary (with MingW) on Windows

What you need:

1) Python (whichever one you want to compile against)
2) MingW (Stable or Candidate)

Setup Instructions:

1) Install Python

2) Install MingW using the Complete option (this may take a while as it usually downloads all the items it needs)

3) In Windows XP/2000 go to Start, then Settings, and choose Control Panel

4) Double-click the item named System

5) You should see the screen below:

6) Click the Environment Variables button

7) Look in the box labeled System Variables (see below) and choose the Path variable. Click the Edit button

8) Add the following values (adjust as necessary for your installation paths):   

     C:\MingW\bin        C:\Python2x  

9) Click OK to accept the new values. Then click OK twice more to close all the other dialogs.

10) Go to C:\Python24\Lib\distutils and create a file named "distutils.cfg" using a text editor, such as Notepad

11) Put the following text into the file:

compiler = mingw32

12) This forces distutils to use the MingW32 compiler to compile your extension. If you hadn't done this, it would try to compile against the compiler found in the Python distribution's header files. In the case of Python 2.4 and 2.5, that would be Visual Studio 2003. You would receive an error telling you as much.

13) Now you're ready to compile an extension.


Let's Compile!

1) Download a package or module that you'd like to compile. If it's zipped, unzip it to a convenient location.

2) Open a command window by going to Start, Run and typing cmd

3) Change directories until you're in the one with the package you downloaded, using the cd command

4) Type the following:    python setup.py bdist_wininst 

5) I have an example screenshot showing how I did it with PyCrypto below. Note that I saved PyCrypto to an temp folder in my L:\ drive. You'll have to change to where ever you placed your files:

That's all there is to it!

A note of caution: If you go to the PEAK website, do NOT use the "Easy Setup" to update your system. It downloads a broken version of distutils as of Oct. 6th, 2007. If you have Python 2.4 or higher, you don't need to download anything except maybe the setup-tools package, which can be found on PyPI.



Get these instructions in the following formats:

Creating Python Binaries.pdf (Portable Document Format - PDF)  - 47 KB
Creating Python Binaries.doc (Microsoft Word Document) - 69 KB
distutils.cfg    (For those too lazy to create the file themselves)