Solve Error – Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed

Solve Error – Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed is a Python error which occurs when libxml does not have the required dependencies and modules installed.

In this article I am going to try and solve the error while I try to explain why the error is actually happening , we will also introduce some solutions that have worked for other developers and see if those solutions can solve the error in your particular situation.

Explaining the Error – Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed

The error happens when you are installing or you want to install libxml but you do not have the required dependencies or modules installed on your machine.

The error is easy to replicate, just try to use pip to install libxml. Like in the line of code bellow.

                                                                       #
pip install libxml2
                                                                       #

This is the message of the error that we get.

                                                                       #
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
                                                                       #

Bellow are the solutions which have worked for me and will help you to successfully solve your issue.

Solution 1 : download and install the precompiled version of libxml

We have explained why the error happens, It is simple you are missing certain modules and dependencies needed by libxml.

The solution is straightforward. You need to install them.

To do that, please visit this official link: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

This is a precompiled version which means it has all the modules and dependencies.

Just look for your python version, download the file. For example, you can download the file: lxml‑4.5.2‑cp37‑cp37‑win32.whl and install it by using the command bellow.

                                                                       #
pip install C:\path\to\downloaded\file\lxml‑4.5.2‑cp37‑cp37‑win32.whl
                                                                       #

I would say with confidence that this fix will solve the issue for most people. If this did not work for you , please try the next solution, it is a solid one.

Solution 2 : install the dependencies manually

This solution is going to show you how to install the dependencies needed manually in both windows and Linux.

The fix in windows is easy, just start by downloading and installing the Cygwin installer.

This is going to help you deal with code designed for Unix-like operating systems. In our example we will use it to install the dependencies.

Starting from here, the steps for windows and Linux will be the same, in Linux start the command prompt and in windows start cygwin.

Then run the commands bellow.

                                                                       #
sudo apt-get install libxml2-dev libxslt1-dev
sudo pip install lxml
sudo yum install libxml2-devel libxslt-devel
                                                                       #

The dependencies are now installed, you should have no error by now.

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up

Guys, this has been my best attempt at helping you understand and solve this issue. I hope you found a solution which suits your needs. Consider helping the blog if you can by donating to our Kofi account.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/