Installing Python 3 lxml on Ubuntu Maverick Meerkat

Installing lxml for Python 3 took me longer than one would expect on Ubuntu 10.10, and since I haven't found much online support online, I thought someone else might benefit from it.

To install lxml for Python 3 on Ubuntu, you will need easy_install3 for python 3:

    sudo apt-get install python3-setuptools

Two packages will be installed: python3-pkg-resources python3-setuptools

If you try using easy_install3 now, you will most likely get an error due to some unmet dependencies:

    ERROR: b'/bin/sh: xslt-config: not found\n'
    ** make sure the development packages of libxml2 and libxslt are installed **

First, you need the development package for libxml2 and the one for libxslt:

    sudo apt-get install libxml2-dev libxslt1-dev

If libxslt1-dev isn't found, try instead libxslt-dev, which will default to libxslt1-dev:

    sudo apt-get install libxslt-dev

Almost there, but you might still get an error when trying to build lxml with easy_install3:

    src/lxml/lxml.etree.c:4: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: Setup script exited with error: command 'gcc' failed with exit status 1

This is due to the fact you need the python 3 development headers as well:

    sudo apt-get install python3-dev

This will install 3 packages: libpython3.1 python3-dev python3.1-dev

Finally, you can install lxml for python 3:

    sudo easy_install3 lxml

and it should go without a problem:

    Installed /usr/local/lib/python3.1/dist-packages/lxml-2.3-py3.1-linux-i686.egg
    Processing dependencies for lxml
    Finished processing dependencies for lxml

Hopefully lxml will have it own package in Natty and in the following releases.