How to build extensions on Windows?

Filip Wasilewski filipwasilewski at
Thu Sep 7 21:11:25 CEST 2006

Kevin D. Smith wrote:
> I've written a simple Python extension for UNIX, but I need to get it
> working on Windows now.  I'm having some difficulties figuring out how
> to do this.  I've seen web pages that say that MS Visual Studio is
> required, and other that say that's not true, that MinGW will work.
> Then there is Mike Fletcher's web page
> ( that describes in
> detail how to build extensions, but most of the links to external
> software are no longer valid.  I think it's safe to say that I am
> completely lost, as there appears to be no authoritative, up-to-date
> description on how to make this work.

There is an easy way to build Python extensions on Windows with MinGW
and it works fine for me. Just follow these steps:

1. Get MinGW gcc and/or g++, preferably via MinGW installer from [1].
You may have to restart your computer or manually edit PATH system
environment variable to include MinGW's bin directory (default is
c:\mingw\bin). Then check if it is there by typing `path` in the cmd

2. Get from [2] and extract pexports.exe file

3. Prepare MinGW compatible .a library file
   pexports.exe c:\WINDOWS\system32\python24.dll > python24.def
   c:\mingw\bin\dlltool.exe --dllname python24.dll --def python24.def
--output-lib libpython24.a

4. Place the new libpython24.a file in the Python's libs directory (but
not in the Lib dir), default is c:\python24\libs

5. Build your extension by executing your setup script with
`--compiler=mingw32` parameter.
   python build --compiler=mingw32

Additionally you may wish to put a distutils.cfg file in the
c:\python\lib\distutils dir containing following entries:
compiler = mingw32

This will tell the distutils script to use MinGW compiler by default
when executing `python build` command.



More information about the Python-list mailing list