src/lxml/etree_defs.h:9:31:致命错误:libxml/xmlversion.h:没有这样的文件或目录

Posted

技术标签:

【中文标题】src/lxml/etree_defs.h:9:31:致命错误:libxml/xmlversion.h:没有这样的文件或目录【英文标题】:src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory 【发布时间】:2013-03-23 10:54:33 【问题描述】:

    我正在运行以下命令来安装该文件中的软件包“ pip install -r requirements.txt --download-cache=~/tmp/pip-cache"。

    requirement.txt 包含像

    这样的包
# Data formats
# ------------
PIL==1.1.7 # 

html5lib==0.90
httplib2==0.7.4
lxml==2.3.1

# Documentation
# -------------
Sphinx==1.1
docutils==0.8.1

# Testing
# -------
behave==1.1.0
dingus==0.3.2
django-testscenarios==0.7.2
mechanize==0.2.5
mock==0.7.2
testscenarios==0.2
testtools==0.9.14
wsgi_intercept==0.5.1

在安装“lxml”包时,我收到以下错误

Requirement already satisfied (use --upgrade to upgrade): django-testproject>=0.1.1 in /usr/lib/python2.7/site-packages/django_testproject-0.1.1-py2.7.egg (from django-testscenarios==0.7.2->-r requirements.txt (line 33))
Installing collected packages: lxml, Sphinx, docutils, behave, dingus, mock, testscenarios, testtools, South
  Running setup.py install for lxml
    Building lxml version 2.3.1.
    Building without Cython.
    ERROR: /bin/sh: xslt-config: command not found

    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
    building 'lxml.etree' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w
    In file included from src/lxml/lxml.etree.c:239:0:
    src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/root/Projects/ir/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-SwjFm3-record/install-record.txt:
    Building lxml version 2.3.1.

Building without Cython.

ERROR: /bin/sh: xslt-config: command not found



** make sure the development packages of libxml2 and libxslt are installed **



Using build configuration of libxslt

running install

running build

running build_py

copying src/lxml/cssselect.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/__init__.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/sax.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/pyclasslookup.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/usedoctest.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/doctestcompare.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/_elementpath.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/ElementInclude.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/builder.py -> build/lib.linux-i686-2.7/lxml

copying src/lxml/html/clean.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/__init__.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/_dictmixin.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/ElementSoup.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/usedoctest.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/defs.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/builder.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/_html5builder.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/diff.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/html5parser.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/_diffcommand.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/_setmixin.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/soupparser.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/html/formfill.py -> build/lib.linux-i686-2.7/lxml/html

copying src/lxml/isoschematron/__init__.py -> build/lib.linux-i686-2.7/lxml/isoschematron

copying src/lxml/etreepublic.pxd -> build/lib.linux-i686-2.7/lxml

copying src/lxml/tree.pxd -> build/lib.linux-i686-2.7/lxml

copying src/lxml/etree_defs.h -> build/lib.linux-i686-2.7/lxml

copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/rng

copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl

copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl

copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1

copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1

copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1

copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1

copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1

copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1

running build_ext

building 'lxml.etree' extension

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w

In file included from src/lxml/lxml.etree.c:239:0:

src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/root/Projects/ir/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-SwjFm3-record/install-record.txt failed with error code 1
Storing complete log in /root/.pip/pip.log

谁能检查并指导我会出现什么问题以及为什么?缺少安装的任何软件包。

【问题讨论】:

【参考方案1】:

    使用安装 Cython

    easy_install Cython

    cython完成后,使用安装libxslt-devel & libxml2-devel

    yum install libxslt-devel libxml2-devel

这对我有用。

【讨论】:

这其实是正确答案(使用sudo apt-get debian/ubuntu) @roshan:对,sudo apt-get install libxml2-dev libxslt1-dev 对于 amazon linux,sudo yum install libxslt-devel libxml2-devell 为我解决了,谢谢 安装库后,Cython 是我缺少的链接。不过,Raspbian 上的软件包只是 -dev。安装 cython 很棘手......我最终不得不使用 sudo pip3 install Cython --install-option="--no-cython-compile" 才能正常工作。 sudo pip3 install Cython 一个人崩溃了,easy_install3 什么也没做【参考方案2】:

安装 libxslt-devel & libxml2-devel 使用

sudo apt-get install libxml2-dev libxslt1-dev

安装后按照上面那个

【讨论】:

Ubuntu 13.04 用户注意事项:如果您已经安装 libxml2 并升级到版本 2.9.0+dfsg1-4ubuntu4.3,您需要通过键入将其降级到 2.9.0+dfsg1-4ubuntu4.1命令 sudo apt-get install libxml2=2.9.0+dfsg1-4ubuntu4.1 否则 libxml2-dev 由于版本依赖性而不会安装。 libxml2和libxml有什么区别?谢谢! 我安装了这两个库,还是报错。注销并重新打开,仍然出现错误。 make 文件在 /usr/include 中查找 libxml,但它嵌套在 libxml2 目录中。从 /usr/include 链接到 libxml 达到了目的sudo ln -s libxml2/libxml libxml 这也是 Debian Jessie 的答案 对于那些使用Alpine Linux(可能在Docker中)的人,命令是:apk add install libxml2-dev libxslt-dev【参考方案3】:

没有 sudo 权限,您可以使用以下命令安装 lxml:

STATIC_DEPS=true pip install lxml

如lxml documentation中所述

【讨论】:

【参考方案4】:

选择的答案是对的,但我只是想为那些使用 Fedora 的人补充一下:libxslt1 在使用 dnf 时被称为 libxslt。所以命令是:

sudo dnf install libxml2-devel libxslt-devel

devel 用于 dnf 与 dev 用于 apt-get。

【讨论】:

【参考方案5】:

经过认证的答案非常有效。但是只是添加了alpine的安装命令来安装libxslt-devel & libxml2-devel

apk add --update libxml2-dev libxslt-dev

【讨论】:

这可能很明显,但通常不需要--update

以上是关于src/lxml/etree_defs.h:9:31:致命错误:libxml/xmlversion.h:没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章