[Flavia Missi] Building and installing lxml with PyPy

Introduction

The major issue my colleagues and I found when we started running some projects with PyPy was the lxml library. It uses Cython, which can run with PyPy if you write your code portably enough. So an effort began to port lxml to use CFFI. This effort can be found on this fork and this is the code we’re going to install from.

Resolving dependencies

We are going to install lxml on a ubuntu 13.04, be warned that installation in OSX might give you serious headaches (<10.8). Start by running the following apt-get:

$ sudo apt-get install libxml2 libxslt1-dev zlib1g-dev

These packages are needed to build lxml (with Python or PyPy).

Bootstraping your environment

You’ll need to have PyPy’s binary to build lxml with, you can folow Andrews Medina’s guide to install it (but it’s in portuguese…)

Assuming you have it installed let’s create a virtual environment (with virtualenv and virtualenvwrapper) to install lxml in:

$ mkvirtualenv lxml-pypy -p /path/to/pypy/bin/pypy

Now clone the lxml fork and checkout to the CFFI branch:

$ git clone https://github.com/amauryfa/lxml.git
$ cd lxml
$ git checkout origin/cffi

Now build and install (double check if you’re in the right virtual environment):

$ python setup.py build
$ python setup.py install

Done!