正在获取“在库libxml2中找不到函数xmlCheckVersion。是否已安装libxml2?” 通过pip安装lxml时

问题:正在获取“在库libxml2中找不到函数xmlCheckVersion。是否已安装libxml2?” 通过pip安装lxml时

Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?尝试通过pip安装lxml时出现错误。

  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

我找不到要通过pip安装的任何libxml2 dev软件包。

在Windows 10下的virtualenv中的x86上使用Python 2.7和Python3.x。

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.


回答 0

我遇到了这个问题,并意识到虽然我确实安装了libxml2,但我没有python软件包所需的必要开发库。安装它们解决了问题:

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

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

回答 1

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml安装适用于您的python版本的lxml 。这是带有所需模块/依赖项的预编译的WHL。

该站点列出了几个软件包,例如,在使用Win32 Python 3.9时,请使用lxml‑4.5.2‑cp39‑cp39‑win32.whl

下载文件,然后安装:

pip install C:\path\to\downloaded\file\lxml4.5.2cp39cp39win32.whl

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

回答 2

尝试使用:
easy_install lxml
这对我有效,win10,python 2.7。

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


回答 3

在Mac OS X El Capitan上,我必须运行以下两个命令来修复此错误:

xcode-select --install
pip install lxml

最终安装了lxml-3.5.0

当您运行xcode-select命令时,您可能必须签署EULA(因此,如果您是在无头计算机上进行操作的,则可以在UI中使用X-Term)。

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


回答 4

如果其他人有与此相同的问题

Centos,尝试:

yum install python-lxml

的Ubuntu

sudo apt-get install -y python-lxml

为我工作。

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.


回答 5

set STATICBUILD=true && pip install lxml

而是运行此命令,必须先安装VS C ++编译器

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

它对我适用于Python 3.5.2和Windows 7

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


回答 6

我尝试安装依赖的库,但lxml没有任何效果。我看到,当构建启动的消息:“建而不用Cython”,所以安装后cython使用apt-get install cythonlxml安装。

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.


回答 7

对我来说,以上解决方案都没有出现并不奇怪,但是我看到了igd安装如何删除新版本并安装了旧版本,对于该解决方案,我下载了此存档:https : //pypi.org/project/ igd /#files

并在setup.py中更改了新版本的推荐版本:“ lxml == 4.3.0”。

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!


回答 8

对于python 32位,我遇到了相同的错误。安装64位后,此问题已解决。

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