I recently had the task of building Python Eggs on Windows that had C extensions. I did the usual googling, and found a few HOWTOs, but nothing I could find was very concise and straightforward. So, I present to you a very concise, very straightforward guide.
Setting up the Build Environment
We are assuming all installers are allowed to install to their default locations.
Download and install Python 2.5 and/or Python 2.4 from python.org. You may have to use Python 2.4.4 since that was the latest 2.4 series to have an installer at time of writing. Whichever you want associated with .py files, install last.
Download and install SetupTools for Python (both 2.4 and 2.5) here.
MingW files are here. Download and run the latest version of “Automated MinGW Installer.” You only need to install g++, and maybe not even that. When it prompts you for old/current/preview version of the MinGW system, select current.
Download and run the current version of “MSYS Base System.”
Open up the MinGW shell, and execute these commands:
cd / mkdir mingw mkdir code #Convenience, if you want to mount your code's dir at an "easy" spot echo "c:/MinGW /mingw c:/path/to/code /code" > /etc/fstab
Create the file
c:\PythonNN\Lib\distutils\distutils.cfg and put the following in it, where NN is replaced with 24 or 25, depending on version::
[build] compiler = mingw32Do this for each version installed.
Building the Eggs
MinGW mounts your drives on the root directory, so your C: drive will be at /c, D: drive at /d, and so on. Open up a MinGW shell, and:
cd /code # or /c/path/to/code, if you didn't mount /code # Depending on which package you're building, you'll either use setup.py # or extended_setup.py. I'm using setup.py here as a placeholder. Replace as appropriate. # Python 2.4: /c/python24/python setup.py build_static # if needed /c/python24/python setup.py bdist_egg # Python 2.5: /c/python25/python setup.py build_static # if needed /c/python25/python setup.py bdist_egg
You’ll now have eggs for your architecture and OS. Enjoy!