【问题标题】:How to install lxml on Windows如何在 Windows 上安装 lxml
【发布时间】:2023-03-02 22:05:01
【问题描述】:

我正在尝试在装有 Python 3.4 的 Windows 8.1 笔记本电脑上安装 lmxl,但失败得很惨。

首先,我尝试了简单明了的解决方案:pip install lxml。然而,这并没有奏效。它是这样说的:

Downloading/unpacking lxml
  Running setup.py (path:C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py) egg_info for package lxml
    Building lxml version 3.4.2.
    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 **

    Using build configuration of libxslt
    C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)

    warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
  Running setup.py install for lxml
    Building lxml version 3.4.2.
    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 **

    Using build configuration of libxslt
    building 'lxml.etree' extension
    C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    error: Unable to find vcvarsall.bat
    Complete output from command C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\CARTE_~1\\AppData\\Local\\Temp\\pip_build_carte_000\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\CARTE_~1\AppData\Local\Temp\pip-l8vvrv9g-record\install-record.txt --single-version-externally-managed --compile:
    Building lxml version 3.4.2.

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 **



Using build configuration of libxslt

running install

running build

running build_py

creating build

creating build\lib.win32-3.4

creating build\lib.win32-3.4\lxml

copying src\lxml\builder.py -> build\lib.win32-3.4\lxml

copying src\lxml\cssselect.py -> build\lib.win32-3.4\lxml

copying src\lxml\doctestcompare.py -> build\lib.win32-3.4\lxml

copying src\lxml\ElementInclude.py -> build\lib.win32-3.4\lxml

copying src\lxml\pyclasslookup.py -> build\lib.win32-3.4\lxml

copying src\lxml\sax.py -> build\lib.win32-3.4\lxml

copying src\lxml\usedoctest.py -> build\lib.win32-3.4\lxml

copying src\lxml\_elementpath.py -> build\lib.win32-3.4\lxml

copying src\lxml\__init__.py -> build\lib.win32-3.4\lxml

creating build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\__init__.py -> build\lib.win32-3.4\lxml\includes

creating build\lib.win32-3.4\lxml\html

copying src\lxml\html\builder.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\clean.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\defs.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\diff.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\ElementSoup.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\formfill.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\html5parser.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\soupparser.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\usedoctest.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\_diffcommand.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\_html5builder.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\_setmixin.py -> build\lib.win32-3.4\lxml\html

copying src\lxml\html\__init__.py -> build\lib.win32-3.4\lxml\html

creating build\lib.win32-3.4\lxml\isoschematron

copying src\lxml\isoschematron\__init__.py -> build\lib.win32-3.4\lxml\isoschematron

copying src\lxml\lxml.etree.h -> build\lib.win32-3.4\lxml

copying src\lxml\lxml.etree_api.h -> build\lib.win32-3.4\lxml

copying src\lxml\includes\c14n.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\config.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\dtdvalid.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\etreepublic.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\htmlparser.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\relaxng.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\schematron.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\tree.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\uri.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\xinclude.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\xmlerror.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\xmlparser.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\xmlschema.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\xpath.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\xslt.pxd -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\etree_defs.h -> build\lib.win32-3.4\lxml\includes

copying src\lxml\includes\lxml-version.h -> build\lib.win32-3.4\lxml\includes

creating build\lib.win32-3.4\lxml\isoschematron\resources

creating build\lib.win32-3.4\lxml\isoschematron\resources\rng

copying src\lxml\isoschematron\resources\rng\iso-schematron.rng -> build\lib.win32-3.4\lxml\isoschematron\resources\rng

creating build\lib.win32-3.4\lxml\isoschematron\resources\xsl

copying src\lxml\isoschematron\resources\xsl\RNG2Schtrn.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl

copying src\lxml\isoschematron\resources\xsl\XSD2Schtrn.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl

creating build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_abstract_expand.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_dsdl_include.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_message.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_skeleton_for_xslt1.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\readme.txt -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1

running build_ext

building 'lxml.etree' extension

C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'

  warnings.warn(msg)

error: Unable to find vcvarsall.bat

----------------------------------------
Cleaning up...
Command C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\CARTE_~1\\AppData\\Local\\Temp\\pip_build_carte_000\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\CARTE_~1\AppData\Local\Temp\pip-l8vvrv9g-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml
Storing debug log for failure in C:\Users\carte_000\pip\pip.log

然后我查看了这个名为 Internet 的伟大而有用的东西,很多人都有同样的错误,需要 libxml2libxlst。他们推荐了一个叫做 Christoph Gohlke 的人的页面,他为一堆包提供了某种二进制文件。你可以找到它here (quicklink to the lxml part)。

所以在我放弃尝试为 pip 寻找 libxml2 和 libxslt 之后,我决定去那里,并发现 绝对吨 的下载。我知道我需要一个 64 位的,但我不知道我需要哪个“cp”。

因此,无论是在 pip 方法或 Gohlke 索引方法上给我一个解决方案的答案都会很棒。

【问题讨论】:

  • 相当肯定cp 在此上下文中表示 C-Python,您应该将其后面的值与您想要支持的 python 版本相匹配。所以cp33 适用于 Python 3.3。
  • 您好lxml可以通过pip轻松安装和更新123,所以请更改接受的答案,让其他人知道无需手动下载和安装whl。
  • 检查 George Answer 伙计们

标签: python windows python-3.x pip lxml


【解决方案1】:

或者你也可以去Christoph's Gohlke's Python page然后下载正确的lxml文件。 (一般因为我用的是python 3.4,而且我有windows,所以我下载的是lxml-3.4.4-cp34-none-win32.whl)

转到它所在的文件夹。在背景中单击(因此未选择任何内容),然后同时左移 + 右键单击​​并单击打开命令窗口。然后输入 C:/Python34/Scripts/pip install "NAME OF THE FILE YOU Just DOWNLOADED.whl"

在这种情况下,它将是 C:/Python34/Scripts/pip install "lxml-3.4.4-cp34-none-win32.whl"

现在按回车键。这对我来说效果很好,在你输入报价后,你也可以按 Tab,它应该会为你填写正确的。

【讨论】:

  • 谢谢!在我使用 python 3.4 的 Win 7 64bit 上,我使用:C:\Python34>pip install lxml-3.4.4-cp34-none-win_amd64.whl
  • 它适用于我的 Win 10 64 位 python 3.7.3。我使用 C:\Users\Admin\Downloads>pip install lxml-4.3.3-cp37-cp37m-win_amd64.whl 因为我的 .whl 文件存在于下载中。
  • 现在每当你想更新 lxml 你必须手动重做?我想念我的 manjaro:(
【解决方案2】:

首先,在 cmets 之后,我下载了 lxml-3.4.2-cp34-none-win_amd64.whl 文件并尝试使用 pip install 打开它,但它只是告诉我它不是我系统上的有效轮子文件或其他东西。

然后,我下载了win_32 文件,它成功了!也许是因为我有一个 Intel 处理器,而 AMD64 不出所料地只适用于 AMD 处理器。

【讨论】:

  • “简而言之,在当今的技术中,AMD64 现在指的是 64 位架构,与 AMD CPU 无关。”来自here
【解决方案3】:

2018 年的今天,lxml 可以从 PyPI 安装:

C:\Users\Administrator>"c:\Program Files\Python37\python.exe" -m pip install -U pip wheel setuptools
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 3.3MB/s
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/5a/9b/6aebe9e2636d35d1a93772fa644c828303e1d5d124e8a88f156f42ac4b87/wheel-0.32.2-py2.py3-none-any.whl
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl (569kB)
    100% |████████████████████████████████| 573kB 2.9MB/s
Installing collected packages: pip, wheel, setuptools
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
  The script wheel.exe is installed in 'c:\Program Files\Python37\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Found existing installation: setuptools 39.0.1
    Uninstalling setuptools-39.0.1:
      Successfully uninstalled setuptools-39.0.1
Successfully installed pip-18.1 setuptools-40.4.3 wheel-0.32.2

C:\Users\Administrator>pip install lxml
Collecting lxml
  Downloading https://files.pythonhosted.org/packages/d7/9d/1aa28aa9d293a816baec6c37328d6465b722b2ff3f4d1e93ed56e87813ee/lxml-4.2.5-cp37-cp37m-win_amd64.whl (3.6MB)
    100% |████████████████████████████████| 3.6MB 1.6MB/s
Installing collected packages: lxml
Successfully installed lxml-4.2.5

C:\Users\Administrator>python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from io import BytesIO
>>> some_file_or_file_like_object = BytesIO(b"<root>data</root>")
>>> from lxml import etree
>>> tree = etree.parse(some_file_or_file_like_object)
>>> etree.tostring(tree)
b'<root>data</root>'

【讨论】:

  • 现在是 2020 年,感谢 George,我可以在 Windows 上使用 pip 安装 lxml。所以现在这应该是公认的答案
【解决方案4】:

这些说明适用于带有 Python3.4 的 Windows7 或 Windows8

但是,随着 python 的发布和其他相应的先决条件的变化/发展,它们应该适用于各种版本:

  1. 安装 Python3.4
    1. 从下载页面HERE下载最新版本的Python3.4
      • Win32 MSI 安装程序的直接链接 -> HERE
    2. 只需运行 MSI 即可安装 python。它将在注册表中注册自己,并出现在“添加/删除程序”中。
    3. 注意:我的说明假设您在 Python 安装向导期间询问时选择将 python 安装到默认路径 C:\python34\
  2. 通过从控制面板>系统>高级系统设置链接(高级选项卡)>环境变量(按钮)
  3. 安装 OpenSSL
    1. HERE 下载Win32 OpenSSL 页面,用于您的Windows 和PC 架构版本
    2. 为您的 Windows 和 PC 架构版本下载 Visual C++ 2008 可再发行组件
    3. 下载 OpenSSL 用于您的 Windows 和体系结构版本(普通版本,而不是轻型版本)
    4. c:\openssl-win32\bin(或类似)目录添加到您的PATH,方法与您在上面添加C:\python34C:\python34\scripts 的方式相同。
  4. 安装 Setuptoolsget-pip.py 应该为您安装 Setuptools),但是,以防万一...
    1. 下载ez_setup.pyHERE并保存到C:\python34\scripts
    2. 运行C:\python34\scripts&gt; python ez_setup.py
  5. 安装 PIP
    1. HERE下载get-pip.py并保存到C:\python34\scripts
    2. 运行C:\python34\scripts&gt; python get-pip.py
  6. 安装 LXML
    1. HERE 下载LXML 3.4.4,用于您的Windows 和PC 架构版本
    2. 运行EXE文件

【讨论】:

  • .exe 文件不再可用于 pypi.org 上的 lxml。
【解决方案5】:

我在列出 lxml==4.2.1 的需求文件中遇到了这个问题。但是,我能够通过将其更新为 lxml==4.2.5 来解决问题。

【讨论】:

  • 这拯救了我的一天,有谁知道为什么 lxml==4.2.5 有效,但 4.2.3 无效
  • This 修复已添加到版本 4.2.4。也许这可能是原因。可以看发布说明here
【解决方案6】:

我最近也遇到了这个问题。 pip 不能处理 .whl 文件。我没有解决这个问题,而是通过 .exe 文件安装它。你可以从here下载它。请选择你的python的正确版本。希望对您有所帮助。

【讨论】:

  • 问题是(一年后,诚然)PyPi 只有轮文件,不再有 .exe :-(
【解决方案7】:

从分销商的网站上,正确的命令是:

pip install lxml==3.4.4

当然,更新版本号以匹配最新版本。

参考:https://pypi.org/project/lxml/3.4.4/

【讨论】:

    【解决方案8】:

    转到此页面 - https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

    下载与您的机器兼容的 libxml。 例如,就我而言,我安装了 64 位英特尔处理器和 python 3.10。 所以,我已经下载了 lxml‑4.6.3‑cp310‑cp310‑win_amd64.whl。

    然后运行-

    pip install "download_path/lxml-4.6.3-cp310-cp310-win_amd64.whl"
    

    【讨论】:

    • 使用 pipwin 从本网站安装
    猜你喜欢
    • 2011-12-16
    • 2017-09-30
    • 1970-01-01
    • 2015-08-10
    • 2020-03-17
    • 1970-01-01
    • 2011-09-24
    • 2016-05-10
    • 2015-07-18
    相关资源
    最近更新 更多