2

I'm trying to install lxml (I need version 3.3.4) but when I try to pip install --upgrade lxml I keep getting build errors:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/tmp/pip_build_root/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-armv6l-2.7/src/lxml/lxml.etree.o -w

gcc: internal compiler error: Killed (program cc1)

Please submit a full bug report,

with preprocessed source if appropriate.

See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.

 error: command 'gcc' failed with exit status 4
----------------------------------------
  Rolling back uninstall of lxml
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-OmT9yH-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/lxml
Storing debug log for failure in /root/.pip/pip.log

This is what the pip log says:

  Removing temporary dir /tmp/pip_build_root...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-OmT9yH-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/lxml
Exception information:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg/pip/req.py", line 706, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg/pip/util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-OmT9yH-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/lxml

This problem only seems to happen on my Raspberry Pi so I'm thinking it's related to ARM? Any ideas?

Output from free -m:

             total       used       free     shared    buffers     cached
Mem:           232         38        193          0          3         17
-/+ buffers/cache:         17        214
Swap:           99         35         64

2 Answers 2

5

Exit status 4 of GCC means that the system doesn't have enough memory. Which Pi are you running with what memory split? Use the free -m command to see how much RAM you have.

If you don't know about the memory split, it's basically how much of the Pi's RAM is allocated to the GPU vs the CPU. You can change it by running sudo raspi-config, then selecting "Advanced Options", then "Memory Split". Set to 16 MB for maximum system memory. You can probably keep it as low as it goes unless you're doing OpenGL ES, in which case turn it back up later.

5
  • Hmm, doesn't seem to help. I still have the same error after changing Memory Split to 16 MB. Maybe I could try 0 MB? I updated the question with output from free -m Apr 18, 2014 at 17:54
  • Well it still doesn't work when I put the memory split to 0 MB. Am I out of luck? Apr 18, 2014 at 18:33
  • 2
    You might be. There are a few ways to get memory usage down further by stopping services, not running X, etc., but I'm not sure how much this would help. You might also try adding more swap (virtual memory). dd if=/dev/zero of=swapfile bs=1M count=256; mkswap swapfile; sudo swapon swapfile If that's still no good, we'll all have to give it some more thought.
    – Fred
    Apr 18, 2014 at 20:28
  • The swapfile trick worked for me as well, thanks Fred! Compiling completed successfully, but took about 45 minutes. So a larger swapfile might help (e.g. count = 512 or 1024 - usually fits easily on an 8 GB SD-card.) One would want lxml because of speed. I'm using it to parse BeautifulSoup4 and speed is not that critical. If it had still failed, I'd have probably chosen an alternative parser rather than dinking around to get lxml working on my 256MB Pi.
    – RolfBly
    Sep 9, 2016 at 10:57
  • 2
    @Fred Would you mind editing the real answer (which is now in the comments) into your answer? That leaves a much better reference for future visitors.
    – Jasper
    Dec 11, 2016 at 23:16
1

I still had this problem today.

I've found an easy way to change the swap size:

  1. Stop the swap using sudo dphys-swapfile swapoff
  2. Edit /etc/dphys-swapfile as root using sudo nano /etc/dphys-swapfile
  3. Find in the file the row containing CONF_SWAPSIZE and change the swap size to what you prefer, I have used CONF_SWAPSIZE=1024
  4. Start the swap again using sudo dphys-swapfile swapon

Happy hacking :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.