Linux – Getting future feature absolute_import is not defined error while installing lxml on centos

centoslinuxpython

I am getting this error while installing libxml

I tried this

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

i tried this as well and it worked

]# 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
>>>

Best Answer

I believe the problem is you have an older version of cython.

Try updating cython with:

pip install "Cython>=0.18"

or similar.

Hope this solves your problem.