Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing lxml module in python

while running a python script, I got this error

  from lxml import etree ImportError: No module named lxml 

now I tried to install lxml

sudo easy_install lmxl 

but it 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 build configuration of libxslt

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 
like image 496
user563101 Avatar asked Jan 04 '11 20:01

user563101


People also ask

Is lxml included in Python?

lxml has been downloaded from the Python Package Index millions of times and is also available directly in many package distributions, e.g. for Linux or macOS.

How do I import lxml into PyCharm?

Settings->Project->Project Interpreter. After this you should see the interpreter that PyCharm uses to run your project. If you don't see lxml in the package's table, you can press the plus icon in the right corner of the window and type lxml and proceed with the installation.

What is lxml package in Python?

lxml is a Python library which allows for easy handling of XML and HTML files, and can also be used for web scraping. There are a lot of off-the-shelf XML parsers out there, but for better results, developers sometimes prefer to write their own XML and HTML parsers.

How do I know if lxml is installed?

You can check if you have the lxml package installed by running the pip show lxml command. Copied! The pip show lxml command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed.


2 Answers

Just do:

sudo apt-get install python-lxml 

For Python 2 (e.g., required by Inkscape):

sudo apt-get install python2-lxml 

If you are planning to install from source, then albertov's answer will help. But unless there is a reason, don't, just install it from the repository.

like image 68
user225312 Avatar answered Sep 21 '22 19:09

user225312


I solved it upgrading the lxml version with:

pip install --upgrade lxml 
like image 24
dbarenas Avatar answered Sep 19 '22 19:09

dbarenas