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

15

131

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.

Slightly answered 18/11, 2015 at 16:49 Comment(0)
S
169

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.11, use lxml‑4.9.0‑cp311‑cp311‑win32.whl.

Download the file, and then install with:

pip install C:\path\to\downloaded\file\lxml‑4.9.0‑cp311‑cp311‑win32.whl
Slightly answered 18/11, 2015 at 16:49 Comment(13)
a not for people having the same problem: 3.4.4. will result in the same error. only version 3.5.0 has gotten me rid of itHierogram
@Hierogram - yum install libxml2-devel libxslt-devel did this for me. #26885014Blinny
You can also install with this more generic command: pip install --use-wheel --find-links=C:\path\to\folder\with\wheel lxmlPolyandry
Perfectly installed under Python 2.7 and W10.Prowler
you should switch to linuxMoriah
I have solved my problem installing libxml2-dev and libxslt-dev in FedoraCoronary
Great help. Another small thing I needed to do: It failed to install on my virtual env (wheel not supported). Eventually I've installed it on my regular python (c:\program files x86...) and copied the python27\lib\site-packages\lxml* folders to the virtual env.Bentinck
gave me lxml... is not a supported wheel on this platform.Breana
@Inspi, match it with Python version installed. For Python version 3.11 it is -cp311-.Schram
@Inspi: ensure you're using the right Python version and ensure you're using the right platform (Win32 <-> 64). Also this can be caused by an outdated PIP, so do a python -m pip install --upgrade pip.Slightly
Excellent. I used amd64 version, and it worked on Windows 10 machine Thank you.Whitford
It seems like lfd.uci.edu/~gohlke/pythonlibs is no longer updated. It says "Archived".Obstetrician
This page sadly no longer exist.Raffle
B
169

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
Biradial answered 8/3, 2016 at 16:12 Comment(5)
Please read through the OPs content. He is doing this on a Windows machine!Gasify
Correct solution for linux when using pipNavigation
Fedora 23: dnf install libxml2-devel and dnf install libxslt-develHistoricity
@Gasify Installing the same packages with the Cygwin installer solves the problem for me on Windows 10.Vaunt
Centos 7: sudo yum install libxml2-devel libxslt-devel (required for python-docx module)Syncarpous
A
38

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

Anastasius answered 23/12, 2015 at 10:35 Comment(2)
it throws the same error when using easy install command for lxmlSuzisuzie
Used to work for me, but now with a new lxml version this no longer works.Slightly
P
28

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).

Pegeen answered 15/1, 2016 at 17:9 Comment(3)
Yup, that do the trick for me in OS X El Capitan. In fact, if you scrolls up the screen to see the root cause of the error, there is a line there says "Perhaps try: xcode-select --install"Amersham
This fixed it, and there is a line that does suggest this as commented above!Fluent
Does anyone else feel like they've run xcode-select --install before, though? Is there any introspection on what this does either a first or second time? As a note, though I did not have to install lxml globally for it to work in a virtual environment, so at least there is that.Speed
E
21

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.

Executor answered 26/5, 2016 at 13:24 Comment(0)
M
10
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

Marmite answered 23/12, 2016 at 1:52 Comment(1)
i have vc2017 installation, trying your answer.Sandysandye
A
2

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.

Acclimate answered 3/5, 2018 at 23:37 Comment(0)
H
2

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*
Halfpint answered 31/10, 2021 at 16:25 Comment(1)
That doesn't seem to include more than the accepted answer.Spent
S
2

For some reason it doesn't work in python 3.11, but 3.10 works.

On windows, to install a module with a previous version, use

py -3.10 -m pip install lxml

if you want to install it in a venv, then use

py -3.10 -m venv .venv
.venv/Scripts/pip.exe install lxml

if you've set up the venv, then you can just use

pip install lxml

You also need to run the python program with that version. If you set up a venv, then you don't need to do this.

py -3.10 file.py
Secular answered 20/11, 2022 at 0:11 Comment(2)
py -3.10 -m pip install lxml gave me the exact same errorBreana
Are you using python 32-bit or 64-bit?Secular
A
1

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!

Autotomize answered 31/1, 2019 at 18:1 Comment(0)
G
0

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

Gettings answered 21/3, 2020 at 6:22 Comment(0)
O
0

On MacOS Big Sur, I ran xcode-select --install as suggested, installed XCode, restarted the Mac, and was still getting the same error when installing lxml.

What helped was to reset the XCode path:

sudo xcode-select --reset

After that, lxml installed successfully.

Ordinal answered 22/6, 2023 at 9:32 Comment(3)
why would you give a Mac answer to an almost 8 year old Windows question? very confused..Paramagnetic
@AndreGreeff I just had the same problem myself, and I'm on Mac, so I spent some time researching it and wanted to share my answer for people having the same problem. I know that the question is about Windows, but I see other non-Windows answers, so I thought mine can be helpful as well.Ordinal
fair enough.. in hindsight, I guess this also helps to show future visitors that there was "more recent" activity on the issue.Paramagnetic
L
0

Download the compiled WHL provided on GitHub project release page https://github.com/lxml/lxml/releases

Them install using the pip command

python -m pip install --upgrade path/to/lxml.whl
Leuko answered 30/11, 2023 at 14:23 Comment(0)
O
0

When I worked on the python:3.9-alpine Docker image, I used this build process to install the build dependencies while compiling for several architectures. The lxml package is in the requirements.txt file.

RUN apk add libxslt libxml2 libxslt-dev libxml2-dev gcc libc-dev \
 && echo "cython < 4.0" > constraints.txt \
 && export PIP_CONSTRAINT=constraints.txt \
 && pip install --upgrade --no-cache-dir pip \
 && pip install --upgrade --no-cache-dir -r requirements.txt \
 && apk del libxslt-dev libxml2-dev gcc libc-dev

source

Note: I am unsure what to uninstall.

Osy answered 7/4 at 21:36 Comment(0)
H
-1

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.

Hardtop answered 27/5, 2021 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.