Usually extension modules for Python on Windows come as an installer, in which everything is precompiled. If you want to compile an extension module yourself and you have Microsoft Visual studio, you can simply run
python setup.py install. This will default to the
cl.exe compiler, which is part of Microsoft Visual Studio. If you don't have Microsoft Visual Studio, or (as in my case) your version of Microsoft Visual Studio is in Japanese and you can't read a thing the compiler is trying to tell you, you can use Cygwin instead.
For this to work, you will need a gcc-style Python library, which you can download below. To create one yourself, first download
pexports, which was written by Anders Norlander and modified by Paul Sokolovsky. It is available in many places, for example here. Or you can search for it with Google. Now run
pexports on the
python24.dll library, which should be somewhere on your hard drive (I found mine in
C:\WINNT\system32). Of course, the file name depends on which Python version you are using. Run
pexports python24.dll > python24.def
This will create a file called
python24.def. Next, you should run
dlltool. You probably already have this on your hard drive, it comes with Cygwin (look for
Devel in Cygwin's
setup program), otherwise you can get it from mingw. Run
dlltool --dllname python24.dll --def python24.def --output-lib libpython24.a
where again the exact file names depend on your Python version. Here, you are using the
python24.def file you just created. Put the resulting
libpython24.a file in
c:\python24\libs\ (in the same directory as
Download: (depending on your browser, you may have to right-click on the link and choose "Save link target as...")
Python 2.1: libpython21.a, python21.def.
Python 2.2: libpython22.a, python22.def.
Python 2.3: libpython23.a, python23.def.
Python 2.4: libpython24.a, python24.def.
Once you have the
libpython2?.a file, you can compile extension modules for Python on Windows using Cygwin. From the Cygwin command prompt, type
/cygdrive/c/Python24/python setup.py build --compiler=mingw32
/cygdrive/c is Cygwin's way of referring to the
C:\ drive. Your path may be different depending on where you installed Python. To install the extension module, type
/cygdrive/c/Python24/python setup.py build --compiler=mingw32 install
If instead you want to create a Windows installer for the extension module, type
/cygdrive/c/Python24/python setup.py build --compiler=mingw32 bdist_winsint