[Django]-Installing lxml with pip in virtualenv Ubuntu 12.10 error: command 'gcc' failed with exit status 4

25👍

Here is the my saved note.

sudo apt-get install libxml2
sudo apt-get install libxslt1.1
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install python-libxml2
sudo apt-get install python-libxslt1
sudo apt-get install python-dev
sudo apt-get install python-setuptools

easy_install lxml

It has worked for my ubuntu 12.10

73👍

Make sure you have enough memory. Try dmesg | tail to see if it outputs something like:

...
[3778136.277570] Out of memory: Kill process 21267 (cc1) score 557 or sacrifice child
[3778136.277587] Killed process 21267 (cc1) total-vm:365836kB, anon-rss:336228kB, file-rss:0kB
👤Matmas

18👍

According to lxml site you could use such construction:

CFLAGS="-O0"  pip install lxml

installation guide

Note for those installing globally: The proper way to pass environment variables with sudo is after sudo:

sudo CFLAGS="-O0" pip install lxml

8👍

I met the similar question(error: command ‘gcc’ failed with exit status 4) this morning. It seems you need check your machine’s memory. If the memory is lower than 512M,that may be the cause.Try to close some services temporarily,like apache server,and try “pip install lxml” again.It maybe work!

3👍

I’ve stumbled with this trouble a couple of times.

Short answer

Python2: $ python2.7 setup.py clean build --with-cython install
Python3: $ pip-3.3 install lxml

Long answer

The hypothesis is that pip install lxml should work in every environment, regardless if you are using Python2 or Python3.

There’s also Cython to be considered: You will certainly enjoy lxml compiled with Cython due to relevant performance gains.

For reasons unknown to me, the compilation on Python2 does not find Cython.
To be more precise and absolutely explicit about this matter, both commands below DO NOT employ Cython:

# DO NOT use these commands. I repeat: DO NOT use these commands.
$ pip-2.7 install lxml
$ easy_install-2.7 install lxml

So, when using Python2 you have only one alternative, as far as I know, which is: compile from sources, Luke!

# install build environment and dependencies
$ kernel_release=$( uname -r )
$ sudo apt-get install linux-headers-${kernel_release} build-essential -y
$ sudo apt-get install libxml2-dev libxslt1-dev -y

# Download from github and compile from sources
$ git clone --branch lxml-3.2.4 https://github.com/lxml/lxml
$ python2.7 setup.py clean build --with-cython install

2👍

For ubuntu 12.04 and virtual env:

sudo apt-get install libxml2-dev libxslt-dev
workon some-virt-env
pip install lxml

2👍

Try to disable the C compiler optimizations by setting the FLAGS environment variable

CFLAGS="-O0"  pip install lxml 

That solves for me without the need of more RAM

Leave a comment