【问题标题】:Installing lxml, libxml2, libxslt for Python 3.5 on Windows 10在 Windows 10 上为 Python 3.5 安装 lxml、libxml2、libxslt
【发布时间】:2016-11-06 00:11:57
【问题描述】:

我首先尝试为它运行基本的 pip install 命令:

C:\Program Files (x86)\Python35-32>pip install lxml
Collecting lxml
  Using cached lxml-3.6.4.tar.gz
Building wheels for collected packages: lxml
  Running setup.py bdist_wheel for lxml ... error
  Complete output from command "c:\program files (x86)\python35-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\Djidiouf\\AppData\\Local\\Temp\\pip-build-ovqa6ncd\\lxml\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\Djidiouf\AppData\Local\Temp\tmp9hzx5gztpip-wheel- --python-tag cp35:
  Building lxml version 3.6.4.
  Building without Cython.
  ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
  ** make sure the development packages of libxml2 and libxslt are installed **


  C:\Users\Djidiouf\AppData\Local\Temp\xmlXPathInitbqgvj3pt.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:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

    ----------------------------------------
Command ""c:\program files (x86)\python35-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\Djidiouf\\AppData\\Local\\Temp\\pip-build-ovqa6ncd\\lxml\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Djidiouf\AppData\Local\Temp\pip-kk7fdpzx-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Djidiouf\AppData\Local\Temp\pip-build-ovqa6ncd\lxml\

我尝试安装 libxml2:

C:\Program Files (x86)\Python35-32>pip install libxml2
Collecting libxml2
  Could not find a version that satisfies the requirement libxml2 (from versions: )
No matching distribution found for libxml2

我还尝试安装 libxslt:

C:\Program Files (x86)\Python35-32>pip install libxslt
Collecting libxslt
  Could not find a version that satisfies the requirement libxslt (from versions: )
No matching distribution found for libxslt

我也尝试从源代码 (https://github.com/lxml/lxml) 构建 lxml,但它也需要 libxml2 依赖项。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 下载 lxml 文件后,我也尝试使用 wheel 安装它:

C:\Program Files (x86)\Python35-32>pip install C:\Users\Djidiouf\Downloads\lxml-3.6.4-cp35-cp35m-win_amd64.whl
lxml-3.6.4-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.

这个 Wheel 文件似乎不支持 Windows 10 或 Python 3.5。

任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试下载以您的 python 版本命名的文件? (cp35,不是 cp36
  • lxml 需要 C/C++ 库 libxml2libxslt - 您无法使用 pip 安装它们
  • @MatsLindh 抱歉,我尝试了 cp36 和之前的 cp35,但只复制粘贴后面的输出,我编辑了我的问题。所以是的,我尝试并得到了完全相同的结果。
  • 至于lxml,我认为您使用的是32位Python,所以您需要32位whl - 名称为win32
  • 好 :) 现在你必须学习如何使用 lxml :) 祝你好运。

标签: python lxml


【解决方案1】:

lxml 使用 libxml2libxslt(在后台)但 libxml2libxslt 不是 Python 模块 - 它是 C/C++ 库。所以你不能使用 pip 安装它们。您必须手动下载并安装它们。

您可以在 Unofficial Windows Binaries for Python Extension Packages 上找到适用于 Windows 的预编译 lxml

  • 文件名中的 cp35 表示 Python 3.5 的版本。
  • 文件名中的win32 表示 32 位 Python 的版本。
  • 文件名中的amd64 表示 64 位 Python 的版本。

您可能使用 32 位 Python,因为我在您的路径中看到了 32(x86)

C:\program files (x86)\python35-32\python.exe

您也应该在此页面上找到指向libxml2libxslt 的链接。该库具有 .dll 和 .exe 文件,您可以将它们放在 PATH 变量中的任何文件夹中。库大多安装在C:\Windows 或子文件夹中。

libxml2libxslt 可能还有 C/C++ 头文件 *.h,您在编译 lxml 时可能需要这些文件。 (在 Linux 上,此文件位于单独的包中 libxml2-dev, libxslt-dev)


顺便说一句:您可以使用Anaconda 分发(而不是Python.org 分发)。它安装了相同的 Python 但带有一些预编译模块 - 即。它会自动安装lxmlAnaconda 可能是 Windows 用户的最佳解决方案。

所有模块列表:https://docs.continuum.io/anaconda/pkg-docs

【讨论】:

  • "该库有 .dll 和 .exe 文件,您可以将它们放在 PATH 变量中的任何文件夹中。库大多安装在 C:\Windows 或子文件夹中。"这是我不明白的部分。如果由于“此平台不支持轮子”而无法使用 pip,我们如何实际安装轮子?只是将轮子放在 Windows 文件夹中不会有任何作用吗?
  • @Calydon 我不谈论 python 的模块,而是谈论使用 C/C++ 创建的库,您可以将其下载为 .zip 文件。 Python 的模块lxml 需要它们才能正确运行。
  • 因为这是关于此主题的最新帖子(或最新帖子)之一。我在lxml==4.5.1 和 Windows 10、python 3.9 中遇到了这些问题。我最终安装了支持 C++ 和 pip install setuptools 的 Visual Studio 并切换到 lxml==4-6-2 并且令人惊讶的是它起作用了。不需要预编译的二进制文件。
【解决方案2】:

另外,检查您的 pip --version。我有 v19.0 和 Gohlke .whl 二进制文件不会安装。升级到 19.2 或更高版本。

【讨论】:

    猜你喜欢
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 2017-09-06
    • 2016-10-05
    • 1970-01-01
    相关资源
    最近更新 更多