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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33785755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:59:34  来源:igfitidea点击:

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

python

提问by SaeX

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

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

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

我没有找到任何要通过 pip 安装的 libxml2 开发包。

Using Python 2.7.10 on x86 in a virtualenv under Windows 10.

在 Windows 10 下的 virtualenv 中在 x86 上使用 Python 2.7.10。

采纳答案by SaeX

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

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

The site lists several packages, when e.g. using Win32 Python 2.7, use lxml-3.6.1-cp27-cp27m-win32.whl.

该站点列出了几个包,例如,当使用 Win32 Python 2.7 时,请使用lxml-3.6.1-cp27-cp27m-win32.whl.

Download the file, and then install with

下载文件,然后安装

pip install C:\path\to\downloaded\file\lxml-3.6.1-cp27-cp27m-win32.whl

回答by Zing Lee

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

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

回答by Jason D

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

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

xcode-select --install
pip install lxml

Which ended up installing lxml-3.5.0

最终安装了 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).

当您运行 xcode-select 命令时,您可能需要签署 EULA(因此,如果您在无头机器上执行此操作,请为 UI 准备一个 X-Term)。

回答by practual

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:

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

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

回答by J1MF0X

In case anyone else has the same issue as this on

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

Centos, try:

Centos,试试:

yum install python-lxml

Ubuntu

Ubuntu

sudo apt-get install -y python-lxml

worked for me.

为我工作。

回答by BigDav

set STATICBUILD=true && pip install lxml

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

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

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

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

它适用于 Python 3.5.2 和 Windows 7

回答by gabrieloliveira

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

我尝试安装一个依赖的库,但lxml没有任何效果。我在构建开始时看到一条消息:“Building without Cython”,所以在安装cythonapt-get install cythonlxml安装了。

回答by Ivan Minakov

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

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

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

并更改了新版本的推荐版本: setup.py 中的 'lxml==4.3.0' 有效!

回答by Nishara MJ

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

我在 python 32 位上遇到了同样的错误。安装64位后,问题得到解决。