Getting "Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?" when installing lxml through pip

Python

Python Problem Overview


I'm getting an error Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed? when trying to install lxml through pip.

  c:\users\f\appdata\local\temp\xmlXPathInitqjzysz.c(1) : fatal error C1083: Cannot open include file: 'libxml/xpath.h': No such file or directory
  *********************************************************************************
  Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
  *********************************************************************************
  error: command 'C:\\Users\\f\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2

I don't find any libxml2 dev packages to install via pip.

Using Python 2.7 and Python 3.x on x86 in a virtualenv under Windows 10.

Python Solutions


Solution 1 - Python

I had this issue and realised that whilst I did have libxml2 installed, I didn't have the necessary development libraries required by the python package. Installing them solved the problem:

sudo apt-get install libxml2-dev libxslt1-dev
sudo pip install lxml

Solution 2 - Python

Install lxml from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml for your python version. It's a precompiled WHL with required modules/dependencies.

The site lists several packages, when e.g. using Win32 Python 3.9, use lxml‑4.5.2‑cp39‑cp39‑win32.whl.

Download the file, and then install with:

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

Solution 3 - Python

Try to use:
easy_install lxml
That works for me, win10, python 2.7.

Solution 4 - Python

On Mac OS X El Capitan I had to run these two commands to fix this error:

xcode-select --install
pip install lxml

Which ended up installing lxml-3.5.0

When you run the xcode-select command you may have to sign a EULA (so have an X-Term handy for the UI if you're doing this on a headless machine).

Solution 5 - Python

In case anyone else has the same issue as this on

> Centos, try:

yum install python-lxml

> Ubuntu

sudo apt-get install -y python-lxml

worked for me.

Solution 6 - Python

set STATICBUILD=true && pip install lxml

run this command instead, must have VS C++ compiler installed first

https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/

It works for me with Python 3.5.2 and Windows 7

Solution 7 - Python

I tried install a lib that depends lxml and nothing works. I see a message when build was started: "Building without Cython", so after install cython with apt-get install cython, lxml was installed.

Solution 8 - Python

It is not strange for me that none of the solutions above came up, but I saw how the igd installation removed the new version and installed the old one, for the solution I downloaded this archive:https://pypi.org/project/igd/#files

and changed the recommended version of the new version: 'lxml==4.3.0' in setup.py It works!

Solution 9 - Python

I got the same error for python 32 bit. After install 64bit, the problem was fixed.

Solution 10 - Python

I had this issue and realized that while I did have libxml2 installed, I didn't have the necessary development libraries required by the python package.

1) Installing them solved the problem:

The site to download the file: Download

2) After Installing the file save it in a accessible folder

pip install *path to that file*

Solution 11 - Python

I am using venv.

In my case it was enough to add lxml==4.6.3 to requirements.txt.

One library wanted earlier version and this was causing this error, so when I forced pip to use newest version (currently 4.6.3) installation was successful.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaeXView Question on Stackoverflow
Solution 1 - PythonpractualView Answer on Stackoverflow
Solution 2 - PythonSaeXView Answer on Stackoverflow
Solution 3 - PythonZing LeeView Answer on Stackoverflow
Solution 4 - PythonJason DView Answer on Stackoverflow
Solution 5 - PythonJ1MF0XView Answer on Stackoverflow
Solution 6 - PythonBigDavView Answer on Stackoverflow
Solution 7 - PythongabrieloliveiraView Answer on Stackoverflow
Solution 8 - PythonIvan MinakovView Answer on Stackoverflow
Solution 9 - PythonNishara MJView Answer on Stackoverflow
Solution 10 - PythonPranava Amirdan PView Answer on Stackoverflow
Solution 11 - PythonKarol ZlotView Answer on Stackoverflow