Matt Seymour

When installing the lxml library from pip you may encounter errors during the install if a number of prerequisite files are not installed to your system. In ubuntu or debian these errors come in the form of:

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w                                                                    
In file included from src/lxml/lxml.etree.c:111:0:                                                                                                                                                             
src/lxml/etree_defs.h:53:31: fatal error: libxml/xmlversion.h: No such file or directory                                                                                                                       
 #include "libxml/xmlversion.h"                                                                                                                                                                                
                               ^                                                                   
compilation terminated.                                                                  
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

To resolve these errors two libraries will need to be downloaded from apt.

sudo apt install libxml2-dev libxmlsec1-dev

Once installed re-run pip install lxml in your environment.