仍然无法正确安装lxml 2.3,但至少2.2.8可用

6 投票
5 回答
5405 浏览
提问于 2025-04-16 19:57
  • 2011年6月30日 -- 我想给@Pablo这个问题一个奖励,因为他的回答。我还是无法正确安装lxml 2.3,原因在他的评论中讨论过。我觉得稍微做点工作可能可以解决,但我已经在这个问题上花了太多时间。不过,我写了我需要的代码,并成功安装了lxml 2.2.8。这个版本的代码运行正常。更好的是,Pablo是唯一一个正确诊断出错误的人。错误是libxslt需要更新到一个支持exsltMathXpathCtxtRegister的版本。感谢大家对这个问题的帮助。

  • 2011年6月29日 -- 更新这个问题以反映评论,并更详细地记录我的尝试


我应该先说,我尝试了所有可能的解决方案和安装场景。是的,确实有类似的问题,但他们的具体问题和解决方案并不是我的。我在这个问题上花了大约10到15个小时,结果只让我更加困惑。

我主要的担忧

简而言之,在CentOS 5.6上从源代码安装lxml-2.3使用easy_install-2.7 lxml安装Python 2.7后,我无法正确导入这个模块。它安装时没有明显的错误,但在尝试导入etree时返回以下错误:

Python 2.7.2 (default, Jun 16 2011, 11:53:48) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>> from lxml import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python2.7/site-packages/lxml-2.3-py2.7-linux-x86_64.egg/lxml/etree.so: undefined symbol: exsltMathXpathCtxtRegister

我尝试过的

  1. 我遇到的两个最常见的建议是确保安装了libxml2 && libxml2-devlibxslt1 && libxslt1-dev。我通过yum安装了它们。

    $ yum list libxslt libxslt-devel libxml2 libxml2-devel 加载插件: fastestmirror 已安装的包 libxml2.i386
    2.6.26-2.1.2.8.el5_5.1 已安装 libxml2.x86_64
    2.6.26-2.1.2.8.el5_5.1 已安装 libxml2-devel.i386
    2.6.26-2.1.2.8.el5_5.1 已安装 libxml2-devel.x86_64
    2.6.26-2.1.2.8.el5_5.1 已安装 libxslt.i386
    1.1.17-2.el5_2.2 已安装 libxslt.x86_64
    1.1.17-2.el5_2.2 已安装 libxslt-devel.i386
    1.1.17-2.el5_2.2 已安装 libxslt-devel.x86_64
    1.1.17-2.el5_2.2 已安装

  2. 重新安装并确认zlib && zlib-devel已安装。

    $ yum list zlib zlib-devel 加载 插件:fastestmirror 已安装 包 zlib.i386
    1.2.3-3 已安装 zlib.x86_64
    1.2.3-3 已安装 zlib-devel.i386
    1.2.3-3 已安装 zlib-devel.x86_64
    1.2.3-3 已安装

  3. 确认python-devel已安装。我想是的。

    a. 根据我读到的几件事,检查python-devel是否安装的一种方法是import distutils。重新搜索这个问题会很快找到这个链接

    b. @Keith建议我尝试“安装”它,使用这个链接,但我遇到了一个错误。

        > error: cannot create %sourcedir /usr/src/redhat/SOURCES
    

    所以,我创建了目录,并且已经安装了。但没有成功。

  4. 不过,我可以import xml.etree.cElementTree as etree和/或import xml.etree.ElementTree as etree,但我确实需要一些来自lxml.etree的特定功能。

  5. 奇怪的是,如果我尝试在假设依赖项未安装的情况下安装lxml,并尝试以下操作:

    sudo STATIC_DEPS=true easy_install-2.7 lxml 2>&1 | tee -a ~/.lxml

    它会失败,并输出以下错误。简单说一下,对于不熟悉的人来说,这似乎解决了很多人的问题,因为它会去获取任何依赖项并安装它们以安装lxml。

    tail -100 ~/.lxml

    gcc -DHAVE_CONFIG_H -I. -I./include -I./include -D_REENTRANT -I/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/include -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -c runsuite.c gcc -DHAVE_CONFIG_H -I. -I./include -I./include -D_REENTRANT -I/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/include -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -c testchar.c testapi.c: 在函数 ‘test_xmlBufferSetAllocationScheme’: testapi.c:18773: 警告: 比较 不同指针类型缺少强制转换 gcc -DHAVE_CONFIG_H -I. -I./include -I./include -D_REENTRANT -I/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/include -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -c testdict.c gcc -DHAVE_CONFIG_H -I. -I./include -I./include -D_REENTRANT -I/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/include -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -c runxmlconf.c gcc -DHAVE_CONFIG_H -I. -I./include -I./include -D_REENTRANT -I/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/include -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -module -no-undefined -avoid-version -rpath /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -o testdso.la testdso.lo testapi.c: 在顶层: testapi.c:17989: 警告: ‘gen_xmlSchematronPtr’ 定义但未使用 testapi.c:17992: 警告: ‘des_xmlSchematronPtr’ 定义但未使用 testapi.c:18009: 警告: ‘gen_xmlSchematronParserCtxtPtr’ 定义但未使用 testapi.c:18012: 警告: ‘des_xmlSchematronParserCtxtPtr’ 定义但未使用 testapi.c:34157: 警告: ‘gen_xmlSAXHandlerPtr_ptr’ 定义但未使用 testapi.c:34160: 警告: ‘des_xmlSAXHandlerPtr_ptr’ 定义但未使用 libtool: link: ar cru .libs/testdso.a testdso.o libtool: link: ranlib .libs/testdso.a libtool: link: ( cd ".libs" && rm -f "testdso.la" && ln -s "../testdso.la" "testdso.la" ) /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -version-info 9:8:7 -ldl -o libxml2.la -rpath /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib SAX.lo entities.lo encoding.lo error.lo parserInternals.lo parser.lo tree.lo hash.lo list.lo xmlIO.lo xmlmemory.lo uri.lo valid.lo xlink.lo HTMLparser.lo HTMLtree.lo debugXML.lo xpath.lo xpointer.lo xinclude.lo nanohttp.lo nanoftp.lo DOCBparser.lo catalog.lo globals.lo threads.lo c14n.lo xmlstring.lo xmlregexp.lo xmlschemas.lo xmlschemastypes.lo xmlunicode.lo xmlreader.lo relaxng.lo dict.lo SAX2.lo xmlwriter.lo legacy.lo chvalid.lo pattern.lo xmlsave.lo xmlmodule.lo schematron.lo -lz -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -liconv -lm ?g' \ < ./xml2Conf.sh.in > xml2Conf.tmp \ && mv xml2Conf.tmp xml2Conf.sh /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o xmllint xmllint.o ./libxml2.la -lz -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -liconv -lm /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o xmlcatalog xmlcatalog.o ./libxml2.la -lz -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -liconv -lm /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o testSchemas testSchemas.o ./libxml2.la -lz -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -liconv -lm /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o testRelax testRelax.o ./libxml2.la -lz -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -liconv -lm libtool: link: gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o testSAX testSAX.o ./libxml2.la -lz -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -liconv -lm libtool: link: gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o testRelax testRelax.o ./.libs/libxml2.a -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -ldl -lz /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib/libiconv.a -lm libtool: link: gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o xmlcatalog xmlcatalog.o ./.libs/libxml2.a -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -ldl -lz /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib/libiconv.a -lm libtool: link: gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o testSchemas testSchemas.o ./.libs/libxml2.a -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -ldl -lz /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib/libiconv.a -lm libtool: link: gcc -g -O2 -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -o xmllint xmllint.o ./.libs/libxml2.a -L/tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib -ldl -lz /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2/lib/libiconv.a -lm ./..libs/libxml2.a(/.xmlIO.o):libs 在函数xmlGzfileOpenW': //tmp/libxml2.aeasy_install-(Y2MKTgxmlIO.o/):lxml -2.3/在构建函数/tmp/libxml2xmlGzfileOpenW-': 2.7.8//xmlIO.c:tmp1247/:easy_install -Y2MKTg/lxml-2.3/build/tmp/undefined libxml2-reference2.7.8/xmlIO.c:1247 :到未定义的`gzopen64' ./reference.libs/libxml2.a(xmlIO.o):在函数xmlGzfileOpen_real':gzopen64'

    /./tmp./libs/easy_installlibxml2.a-(xmlIO.oY2MKTg):/lxml- 2.3/在构建函数/tmp/libxml2xmlGzfileOpen_real': -/2.7.8tmp//xmlIO.ceasy_install:1175-Y2MKTg/:lxml- 2.3/build/undefinedtmp /referencelibxml2-2.7.8 /toxmlIO.c :1175: gzopen64未定义' 参考 to gzopen64' collect2: collect2: ld 返回1退出状态 ld 返回1 退出状态 make[2]: *** [testRelax] 错误1 make[2]: *** 等待 未完成的作业.... make[2]: *** [testSAX] 错误1 .././.libs/libslibxml2.a/(libxml2.axmlIO.o(xmlIO.o)):: 在函数 在函数 xmlGzfileOpenW'xmlGzfileOpenW':: / tmp/easy_install-Y2MKTg//tmp/lxmleasy_install--Y2MKTg/lxml2.3-2.3//build/tmp/buildlibxml2-2.7.8//xmlIO.ctmp:/libxml2-1247: 未定义引用 2.7.8gzopen64/xmlIO.c:1247 :未定义' .引用/ .to libs/gzopen64libxml2.a' (./.xmlIO.olibs/libxml2.a(xmlIO.o)): : 在函数xmlGzfileOpenW'xmlGzfileOpenW':: / tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2-2.7.8/xmlIO.c:1247 :未定义' .引用/ .to gzopen64' collect2: ld 返回1退出状态

    collect2: ld 返回1退出状态 ./.libs/libxml2.a(xmlIO.o): 在 函数 xmlGzfileOpenW': /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2-2.7.8/xmlIO.c:1247: 未定义引用到gzopen64' ./.libs/libxml2.a(xmlIO.o): 在 函数 xmlGzfileOpen_real': /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2-2.7.8/xmlIO.c:1175: 未定义引用到gzopen64' collect2: ld 返回1退出状态 make2: * [testSchemas] 错误1 make2: [xmlcatalog] 错误1 make2: [xmllint] 错误1 make2: 离开目录 /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2-2.7.8'

    make[1]: *** [all-recursive] 错误1 make[1]: 离开目录 /tmp/easy_install-Y2MKTg/lxml-2.3/build/tmp/libxml2-2.7.8'

    make: *
    [all] 错误2 回溯 (最近的调用最后): 文件 "/usr/local/bin/easy_install-2.7", 第8行,在 load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install-2.7')() 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第1712行,在主函数中 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第1700行,在使用ei时 文件 "/usr/local/lib/python2.7/distutils/core.py", 第152行,在设置中 dist.run_commands() 文件 "/usr/local/lib/python2.7/distutils/dist.py", 第953行,在运行命令中 self.run_command(cmd) 文件 "/usr/local/lib/python2.7/distutils/dist.py", 第972行,在运行命令中 cmd_obj.run() 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第211行,在运行时 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第446行,在easy_install中 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第476行,在安装项中 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第655行,在安装和构建中 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第930行,在构建和安装中 文件 "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", 第919行,在运行设置中 文件 "build/bdist.linux-i686/egg/setuptools/sandbox.py", 第62行,在运行设置中 文件 "build/bdist.linux-i686/egg/setuptools/sandbox.py", 第105行,在运行时 文件 "setup.py", 第130行,在
    文件 "/tmp/easy_install-Y2MKTg/lxml-2.3/setupinfo.py", 第56行,在ext_modules中 文件 "/tmp/easy_install-Y2MKTg/lxml-2.3/buildlibxml.py", 第311行,在build_libxml2xslt中 文件 "/tmp/easy_install-Y2MKTg/lxml-2.3/buildlibxml.py", 第253行,在cmmi中 文件 "/tmp/easy_install-Y2MKTg/lxml-2.3/buildlibxml.py", 第236行,在调用子进程中 异常:命令"make -j6"返回 代码2

还有很多其他尝试,如果你感兴趣,可以在这里查看。

我尝试过几种其他安装方法,包括@agilevic的,返回的错误几乎与上面的错误相同。大多数其他方法安装都很顺利,但在from lxml import etree时都失败了。

为什么不使用yum呢?好吧,我通过yum install python-lxml轻松安装了lxml,但那是CentOS默认安装的Python 2.4。此时,可能更容易将我现有的项目调整为使用2.4。不过,从长远来看,我确实想解决这个问题。为了我自己,也为了将来可能遇到类似问题的其他人。

5 个回答

1

从你的输出信息来看,链接器出现了一个错误:undefined reference to gzopen64

这个错误在lxml-2.3/buildlibxml.py的第236行被抛出,然后又传递到了make -j6命令中。

我在这里找到一个讨论串:http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=15524,里面也有类似的编译错误,并给出了一个建议:

你可能安装了i586版本的zlib库。你需要安装64位版本的zlib和zlib-devel。

这个讨论串的发帖者后来评论说:

我现在做的是下载zlib的源代码,并在本地环境中编译它。放在/usr/local/includes等地方。然后重新编译了所有插件,再次编译了ImageMagick。

现在它可以正常工作了。非常感谢 :D

所以,我建议你重新安装zlib和zlib-devel,然后再尝试安装lxml。

2

给未来的搜索者们一句话 - 我来到这里时也遇到了同样的问题,但我安装了一个比较新的 libxslt 版本(1.1.26)。大约花了10分钟我才意识到,我的路径中还有一个很老的版本(是通过 casapy 这个天文学软件包安装的)。

这个故事的教训是:运行 locate libxslt 来查找旧版本,并检查你的 $LD_LIBRARY_PATH!(当然,这个方法也适用于任何库的冲突问题)。

2

你的libxslt没有这个exsltMathXpathCtxtRegister,把它去掉,然后手动安装一个更新的版本(1.1.26应该没问题)。

旧版本的lxml也可能可以用,试试用easy_install lxml==2.2.8来安装。

撰写回答