Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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.

like image 601
SaeX Avatar asked Nov 18 '15 16:11

SaeX


People also ask

How do I import LXML?

Open your macOS terminal. Type “ pip install lxml ” without quotes and hit Enter . If it doesn't work, try "pip3 install lxml" or “ python -m pip install lxml “. Wait for the installation to terminate successfully.

Are LXML libxml2 and Libxslt installed?

Unless you are using a static binary distribution (e.g. from a Windows binary installer), lxml requires libxml2 and libxslt to be installed, in particular: libxml2 version 2.9. 2 or later.


2 Answers

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 
like image 128
practual Avatar answered Sep 21 '22 11:09

practual


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 
like image 31
SaeX Avatar answered Sep 21 '22 11:09

SaeX