Installing the MySQLdb Python module on Snow Leopard

Needing to access a MySQL database through Python, I was faced by the inability to easily install the MySQLdb module. I do use MacPorts, but after running the obvious
sudo port install py26-mysql
I realized that I would be downloading, compiling and installing a new instance of Python, a new instance of MySQL (I prefer the simplicity of MAMP), and who knows what else.

Installing the module alone doesn’t work, because MAMP installs no headers; and copying the headers from the vanilla MySQL distribution doesn’t help either, because a few of the required files are generated on the fly during the installation of MySQL itself.

The solution, it turns out, is relatively simple. Follow along. Continue reading “Installing the MySQLdb Python module on Snow Leopard”