在 centos 上安装 lxml 时出现未来功能 absolute_import 未定义错误

在 centos 上安装 lxml 时出现未来功能 absolute_import 未定义错误

安装 libxml 时出现此错误

我试过这个

python27 setup.py build_ext -i  -I /usr/include/libxml2 --with-xslt-config=/opt/xslt/bin/xslt-config

   /opt/python27/lib/python2.7/site-packages/Cython-0.14.1-py2.7-linux-x86_64.egg/Cython/Includes/libc/string.pxd
Compiling src/lxml/lxml.etree.pyx because it changed.
Compiling src/lxml/lxml.objectify.pyx because it changed.

Error compiling Cython file:
------------------------------------------------------------
...
u"""The ``lxml.etree`` module implements the extended ElementTree API
for XML.
"""

from __future__ import absolute_import
                      ^
------------------------------------------------------------

/var/www/html/djangosites/SERVER/temp/lxml-lxml-a9e9f15/src/lxml/lxml.etree.pyx:5:23: future feature absolute_import is not defined
Traceback (most recent call last):
  File "setup.py", line 218, in <module>
    **setup_extra_options()
  File "setup.py", line 130, in setup_extra_options
    STATIC_CFLAGS, STATIC_BINARIES)
  File "/var/www/html/djangosites/SERVER/temp/lxml-lxml-a9e9f15/setupinfo.py", line 147, in ext_modules
    result = cythonize(result)
  File "/opt/python27/lib/python2.7/site-packages/Cython-0.14.1-py2.7-linux-x86_64.egg/Cython/Build/Dependencies.py", line 505, in cythonize
    cythonize_one(pyx_file, c_file, options)
  File "/opt/python27/lib/python2.7/site-packages/Cython-0.14.1-py2.7-linux-x86_64.egg/Cython/Build/Dependencies.py", line 526, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: src/lxml/lxml.etree.pyx

我也尝试过这个并且有效

]# python27
Python 2.7 (r27:82500, May 26 2011, 17:42:13)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import absolute_import
>>>

答案1

我相信问题在于你有一个旧版本的 cython。

尝试使用以下命令更新 cython:

pip install "Cython>=0.18"

或类似的东西。

希望这能解决您的问题。

相关内容