自己找到解决办法了:
Get libxml2-sources-2.6.20.tar.gz from ftp://xmlsoft.org/libxml2. I downloaded mine to /home/hedley/src/libxml2-sources-2.6.20.tar.gz. Note that my version of libxml2 is just an example.
cd /home/hedley/src
tar -xvzf libxml2-sources-2.6.20.tar.gz
cd libxml2-2.6.20
./configure
make
We don't need to install the libraries, so no make install.
cd python
CFLAGS=-I/home/hedley/src/libxml2-2.6.20/include /path/to/Python-2.4.4/bin/python setup.py build
CFLAGS=-I/home/hedley/src/libxml2-2.6.20/include /path/to/Python-2.4.4/bin/python setup.py install
Verify that it worked.
/path/to/Python-2.4.4/bin/python
Python 2.4.4 (#1, Jan 3 2008, 10:11:41)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libxml2
>>> import libxml2mod
If you see no import errors then everything worked!