Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install lxml on Ubuntu

I'm having difficulty installing lxml with easy_install on Ubuntu 11.

When I type $ easy_install lxml I get:

Searching for lxml Reading http://pypi.python.org/simple/lxml/ Reading http://codespeak.net/lxml Best match: lxml 2.3 Downloading http://lxml.de/files/lxml-2.3.tgz Processing lxml-2.3.tgz Running lxml-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7UdQOZ/lxml-2.3/egg-dist-tmp-GacQGy Building lxml version 2.3. Building without Cython. ERROR: /bin/sh: xslt-config: not found  ** make sure the development packages of libxml2 and libxslt are installed **  Using build configuration of libxslt  In file included from src/lxml/lxml.etree.c:227:0: src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory compilation terminated. 

It seems that libxslt or libxml2 is not installed. I've tried following the instructions at http://www.techsww.com/tutorials/libraries/libxslt/installation/installing_libxslt_on_ubuntu_linux.php and http://www.techsww.com/tutorials/libraries/libxml/installation/installing_libxml_on_ubuntu_linux.php with no success.

If I try wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.6.27.tar.gz I get

<successful connection info> ==> SYST ... done.    ==> PWD ... done. ==> TYPE I ... done.  ==> CWD (1) /libxml2 ... done. ==> SIZE libxml2-sources-2.6.27.tar.gz ... done. ==> PASV ... done.    ==> RETR libxml2-sources-2.6.27.tar.gz ...  No such file `libxml2-sources-2.6.27.tar.gz'. 

If I try the other first, I'll get to ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2 and that will fail eventually with:

checking for libxml libraries >= 2.6.27... configure: error: Could not find libxml2 anywhere, check ftp://xmlsoft.org/. 

I've tried both versions 2.6.27 and 2.6.29 of libxml2 with no difference.

Leaving no stone unturned, I have successfully done sudo apt-get install libxml2-dev, but this changes nothing.

like image 341
Eric Wilson Avatar asked Jun 28 '11 10:06

Eric Wilson


People also ask

How do I import lxml into Python?

Open your Linux terminal or shell. Type “ pip install lxml ” (without quotes), hit Enter. If it doesn't work, try "pip3 install lxml" or “ python -m pip install lxml “. Wait for the installation to terminate successfully.

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.


2 Answers

Since you're on Ubuntu, don't bother with those source packages. Just install those development packages using apt-get.

apt-get install libxml2-dev libxslt1-dev python-dev 

If you're happy with a possibly older version of lxml altogether though, you could try

apt-get install python-lxml 

and be done with it. :)

like image 53
AKX Avatar answered Oct 02 '22 21:10

AKX


I also had to install lib32z1-dev before lxml would compile (Ubuntu 13.04 x64).

sudo apt-get install lib32z1-dev 

Or all the required packages together:

sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev 
like image 22
Druska Avatar answered Oct 02 '22 23:10

Druska