install lxml inside python virtualenv [solved]

When trying to install lxml inside virtualenv, I kept getting some compilation error messages.

I already had lxml installed outside virtualenv, i.e. in my global python library. I got it installed via running:

sudo apt-get install python-lxml

This is of no use when using virtualenv since by definition each virtual environment will have it’s own libraries.

As mentioned, pip failed when running:

pip install lxml

Error message:

In file included from src/lxml/lxml.etree.c:239:0:
/tmp/pip-build-gc7tlt4f/lxml/src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory
#include “libxml/xmlversion.h”
^
compilation terminated.

Reason it is occurring is because when installing lxml python library, a compilation occurs.
File not found simply means that some dependency libraries were not met.

Solution was to run:

sudo apt-get install libxml2 libxml2-dev libxslt-dev build-essential zlib1g-dev

After that, “pip install lxml” was successful.

 

 

Post a Comment

Your email is never published nor shared. You're allow to say what you want...