在 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