Install lxml module in python

when running python script, I got this error

from lxml import etree ImportError: No module named lxml 

now i tried installing lxml

 sudo easy_install lmxl 

but this gives me the following error:

 Building lxml version 2.3.beta1. NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' needs to be available. ERROR: /bin/sh: xslt-config: not found ** make sure the development packages of libxml2 and libxslt are installed ** 

Using libxslt build configuration

 src/lxml/lxml.etree.c:4: fatal error: Python.h: No such file or directory compilation terminated. error: Setup script exited with error: command 'gcc' failed with exit status 1 
+76
python lxml python-import
Jan 04 '11 at 20:45
source share
5 answers

Just do:

 sudo apt-get install python-lxml 

For Python 2 (e.g. Inkscape is required):

 sudo apt-get install python2-lxml 

If you plan to install from source, then an alberta response will help. But if there is no reason, do not install it from the repository.

+101
Jan 04 2018-11-11T00:
source share

I decided to upgrade the lxml version with

 pip install --upgrade lxml 
+52
Sep 26 '13 at 17:51
source share

To compile lxml, you need to install the Python header files (the python-dev package in debian / ubuntu). Also like libxml2, libxslt, libxml2-dev and libxslt-dev:

 apt-get install python-dev libxml2 libxml2-dev libxslt-dev 
+49
Jan 04 2018-11-11T00:
source share

If you are using python3 you will need to:

pip3 install lxml

+22
May 02 '16 at 20:13
source share

For RHEL / CentOS, run the python --version command to find out the version of Python. For example. below:

 $ python --version Python 2.7.12 

Now run "sudo yum search lxml" to find out the python * -lxml package.

 $ sudo yum search lxml Failed to set locale, defaulting to C Loaded plugins: priorities, update-motd, upgrade-helper 1014 packages excluded due to repository priority protections ============================================================================================================= N/S matched: lxml ============================================================================================================= python26-lxml-docs.noarch : Documentation for python-lxml python27-lxml-docs.noarch : Documentation for python-lxml python26-lxml.x86_64 : ElementTree-like Python bindings for libxml2 and libxslt python27-lxml.x86_64 : ElementTree-like Python bindings for libxml2 and libxslt 

Now you can select the package according to your version of Python and execute the command as shown below:

 $ sudo yum install python27-lxml.x86_64 
+4
Feb 21 '17 at 12:26
source share



All Articles