How to build extensions on Windows?

casevh at comcast.net casevh at comcast.net
Thu Sep 7 21:45:56 CEST 2006


> 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
> window.

1a. [Optional] Install MSYS, also from [1]. If your extension relies on
another C library, this may make it easier to compile that library.

>
> 2. Get pexports-0.42h.zip 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

I believe steps 2 through 4 are only required for Python 2.3 or
earlier. I have not needed to do those steps for Python 2.4 and 2.5.

>
> 5. Build your extension by executing your setup script with
> `--compiler=mingw32` parameter.
>    python setup.py build --compiler=mingw32
>
> Additionally you may wish to put a distutils.cfg file in the
> c:\python\lib\distutils dir containing following entries:
> [build]
> compiler = mingw32
>
> This will tell the distutils script to use MinGW compiler by default
> when executing `python setup.py build` command.
>
> best,
> fw
>
> [1] http://sourceforge.net/projects/mingw/
> [2] http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip




More information about the Python-list mailing list