构建'lxml.etree'扩展时出错

0 投票
1 回答
1976 浏览
提问于 2025-04-16 01:24

我正在尝试在一个运行Python 2.6的Ubuntu服务器上安装lxml(这个环境是虚拟环境,系统自带的Python是2.5)。

我通过svn下载了代码,并按照说明安装了Cython,具体可以参考这个链接

但是,当我运行python setup.py build时,出现了以下错误:

Building lxml version 2.3.alpha1-76211.
Building with Cython 0.11.
Using build configuration of libxslt 1.1.22
Building against libxml2/libxslt in the following directory: /usr/lib
running build
running build_py
running build_ext
cythoning src/lxml/lxml.etree.pyx to src/lxml/lxml.etree.c

Error converting Pyrex file to C:
------------------------------------------------------------
...
        c_child = _findChildForwards(c_node, 0)
        while c_child is not NULL:
            if c_child.type == tree.XML_ELEMENT_NODE:
                for i in range(c_tag_count):
                    if _tagMatchesExactly(c_child, c_ns_tags[2*i], c_ns_tags[2*i+1]):
                        c_next = _findChildForwards(c_child, 0) or _nextElement(c_child)
                                                               ^
------------------------------------------------------------

/home/admin/web/blink/lxml/src/lxml/cleanup.pxi:246:64: Cannot assign type 'int' to 'xmlNode *'

Error converting Pyrex file to C:


building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/python/2.6.5/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
error: command 'gcc' failed with exit status 1

如果我尝试python setup.py bdist_eggpython setup.py build_ext -i或者make,也会出现类似的错误。

通过easy_install或pip安装时也会出现同样的错误,虽然easy_install会一直卡在那里。

据我所知,所有需要的依赖项,比如python-dev,都是已经安装好的。

我到底漏掉了什么或者做错了什么呢?

1 个回答

1

“我已经通过svn检查了...”

“正在构建lxml版本2.3.alpha1-76211...”

你似乎在使用最新的版本。建议:使用一个已经发布的lxml版本。可以咨询一下lxml的作者或维护者。

撰写回答