【问题标题】:lxml error in python3.4 installationpython3.4安装lxml报错
【发布时间】:2017-10-15 09:06:13
【问题描述】:

我正在尝试在命令提示符下运行以下命令 -

pip install -r requirements.txt

但它显示了很多错误,我不知道如何解决它们,因为我不熟悉 python。

错误是: 1.

Collecting lxml==3.5.0 (from -r requirements.txt (line 1))
  Using cached lxml-3.5.0.tar.gz
Collecting pyquery==1.2.10 (from -r requirements.txt (line 2))
Collecting cssselect>0.7.9 (from pyquery==1.2.10->-r requirements.txt (line 2))




     Using cached cssselect-1.0.1-py2.py3-none-any.whl
        Building wheels for collected packages: lxml
          Running setup.py bdist_wheel for lxml ... error
          Complete output from command c:\python34\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Mohana\\AppData\\Local\\Temp\\pip-build-9bz1xoev\\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\Mohana\AppData\Local\Temp\tmp425xg1fhpip-wheel- --python-tag cp34:
          Building lxml version 3.5.0.
          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 **

2. 

    src\lxml\includes\etree_defs.h(14) : fatal error C1083: Cannot open include file: 'libxml/xmlversion.h': No such file or directory
      Compile failed: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\Bin\\cl.exe' failed with exit status 2
      creating Users
      creating Users\Mohana
      creating Users\Mohana\AppData
      creating Users\Mohana\AppData\Local
      creating Users\Mohana\AppData\Local\Temp
      C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I/usr/include/libxml2 /TcC:\Users\Mohana\AppData\Local\Temp\xmlXPathInitocb5oi7w.c /FoUsers\Mohana\AppData\Local\Temp\xmlXPathInitocb5oi7w.obj
      xmlXPathInitocb5oi7w.c
      C:\Users\Mohana\AppData\Local\Temp\xmlXPathInitocb5oi7w.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 10.0\\VC\\Bin\\cl.exe' failed with exit status 2

3.

Failed building wheel for lxml
  Running setup.py clean for lxml
Failed to build lxml
Installing collected packages: lxml, cssselect, pyquery
  Found existing installation: lxml 4.0.0
    Uninstalling lxml-4.0.0:
      Successfully uninstalled lxml-4.0.0
  Running setup.py install for lxml ... error
    Complete output from command c:\python34\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Mohana\\AppData\\Local\\Temp\\pip-build-9bz1xoev\\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\Mohana\AppData\Local\Temp\pip-rjvm3d2l-record\install-record.txt --single-version-externally-managed --compile:
    Building lxml version 3.5.0.
    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 **


4. 

    src\lxml\includes\etree_defs.h(14) : fatal error C1083: Cannot open include file: 'libxml/xmlversion.h': No such file or directory
        Compile failed: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\Bin\\cl.exe' failed with exit status 2
        C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I/usr/include/libxml2 /TcC:\Users\Mohana\AppData\Local\Temp\xmlXPathInity8a5suic.c /FoUsers\Mohana\AppData\Local\Temp\xmlXPathInity8a5suic.obj
        xmlXPathInity8a5suic.c
        C:\Users\Mohana\AppData\Local\Temp\xmlXPathInity8a5suic.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 10.0\\VC\\Bin\\cl.exe' failed with exit status 2

请帮我解决这些问题,我的项目需要它,我真的需要完成它。我在 Windows 10(英特尔处理器)和 Python3.4 上。

【问题讨论】:

标签: python lxml python-3.4 libxml2 libxslt


【解决方案1】:

正如@SaeX 在this answer 中所说,您可以找到预编译的 带有所需模块和依赖项的 lxml 的 WHL here

对于 Python 3.4 和 win10,您的文件应为 lxml‑4.1.0‑cp34‑cp34m‑win_amd64.whl。然后就可以使用 pip 安装了:

pip install lxml‑4.1.0‑cp34‑cp34m‑win_amd64.whl

【讨论】:

    【解决方案2】:

    对于python 3.4或以上,

    在命令提示符中, 如果您想从网络自动下载和安装,请键入 pip3 install lxml 另外,从下面下载lxml的.whl文件

    对于 32 位:Download Here

    对于 64 位:Download Here

    下载wheel文件后,将命令提示符导航到.whl文件下载的位置,然后尝试 pip3 install "下载的 whl 文件名"

    【讨论】:

      【解决方案3】:

      对于 windows,如果 whl 也失败,您可以通过 exe 文件安装 lxml。可以从lxml下载

      希望对你有帮助。

      【讨论】: