This tutorial will cover how to install lxml in python using pip.

Recently I was trying to install lxml in a docker python container.

I was using pip to install the lxml package from pypi.

However, when trying to install my packages with pip, I was receiving the following error:

Running install for lxml: finished with status 'error'

After some googling and reading the lxml documentation, it seems that lxml requires some extra dependencies in order to install properly.

These dependencies are libxml2-dev, libxslt-dev, and python-dev

In my specific case, I was attempting to install lxml inside a docker container using an alpine python image.

I was able to install the needed dependencies using the following command:

RUN apk add libxml2-dev libxslt-dev python-dev

If you’re on a debian-based system like ubuntu, you can instead use the following command:

sudo apt-get install libxml2-dev libxslt-dev python-dev

The needed lxml dependencies should now be installed. If you now run pip install lxml, everything should install without issue.

I hope that was helpful.

Please check out my other python articles for more python tips, tricks and guides.