The Python Oracle

How to install lxml on Ubuntu

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Jungle Looping

--

Chapters
00:00 Question
01:41 Accepted answer (Score 965)
02:11 Answer 2 (Score 114)
02:35 Answer 3 (Score 45)
02:58 Answer 4 (Score 17)
03:39 Thank you

--

Full question
https://stackoverflow.com/questions/6504...

Question links:
http://www.techsww.com/tutorials/librari...
http://www.techsww.com/tutorials/librari...

Answer 3 links:
[can't installing lxml on Ubuntu 12.04]: https://stackoverflow.com/questions/1989...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #ubuntu #lxml #libxml2 #easyinstall

#avk47



ACCEPTED ANSWER

Score 968


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. :)




ANSWER 2

Score 114


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



ANSWER 3

Score 46


As @Pepijn commented on @Druska 's answer, on ubuntu 13.04 x64, there is no need to use lib32z1-dev, zlib1g-dev is enough:

sudo apt-get install libxml2-dev libxslt-dev python-dev zlib1g-dev



ANSWER 4

Score 17


I installed lxml with pip in Vagrant, using Ubuntu 14.04 and had the same problem. Even though all requirements where installed, i got the same error again and again. Turned out, my VM had to little memory by default. With 1024 MB everything works fine.

Add this to your VagrantFile and lxml should properly compile / install:

config.vm.provider "virtualbox" do |vb|
  vb.memory = 1024
end

Thanks to sixhobbit for the hint (see: can't installing lxml on Ubuntu 12.04).