在 Ubuntu 上安装 lxml 时编译错误

在 Ubuntu 上安装 lxml 时出现编译器错误,错误类似如下:错误:命令‘x86_64-linux-gnu-gcc’失败,退出状态为 4,很可能是由于内存不足导致的。

Solutions

  • Enlarge memory if possible, for example, if the issue was encountered on a virtual machine

  • If enlarging memory is not possible, then add swap file:

sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

See reference.

ubuntu python