How To Install python-lxml on CentOS 7

In this tutorial we learn how to install python-lxml on CentOS 7. python-lxml is ElementTree-like Python bindings for libxml2 and libxslt

Introduction

In this tutorial we learn how to install python-lxml on CentOS 7.

What is python-lxml

lxml provides a Python binding to the libxslt and libxml2 libraries. It follows the ElementTree API as much as possible in order to provide a more Pythonic interface to libxml2 and libxslt than the default bindings. In particular, lxml deals with Python Unicode strings rather than encoded UTF-8 and handles memory management automatically, unlike the default bindings.

We can use yum or dnf to install python-lxml on CentOS 7. In this tutorial we discuss both methods but you only need to choose one of method to install python-lxml.

Install python-lxml on CentOS 7 Using yum

Update yum database with yum using the following command.

sudo yum makecache

After updating yum database, We can install python-lxml using yum by running the following command:

sudo yum -y install python-lxml

Install python-lxml on CentOS 7 Using dnf

If you don’t have dnf installed you can install DNF on CentOS 7 first. Update yum database with dnf using the following command.

sudo dnf makecache

After updating yum database, We can install python-lxml using dnf by running the following command:

sudo dnf -y install python-lxml

How To Uninstall python-lxml on CentOS 7

To uninstall only the python-lxml package we can use the following command:

sudo dnf remove python-lxml

References

Summary

In this tutorial we learn how to install python-lxml on CentOS 7 using yum and dnf.