=Start=
缘由:
没钱租高性能的VPS……
搜索关键字:
- lxml Compile failed: command ‘gcc’ failed with exit status 4
- lxml error: command ‘gcc’ failed with exit status 4
参考解答:
用swap交换分区「扩展」内存容量。
#常规安装方法(失败) ➜ ~ sudo /usr/local/bin/pip install lxml …… gcc: 编译器内部错误:已杀死(程序 cc1) Compile failed: command 'gcc' failed with exit status 4 error: command 'gcc' failed with exit status 4 …… #查看内存情况 ➜ ~ free -m #增加编译选项(有时可行,比如在512m的Ubuntu 12.04/14.04) ➜ ~ CFLAGS="-O0" sudo /usr/local/bin/pip install lxml #查看是否由 OutOfMemory 的错误所导致 ➜ ~ dmesg | tail ➜ ~ sudo cat /var/log/messages | grep -B1 "Killed" #查看磁盘使用情况 ➜ ~ df -h #用多余的磁盘空间创建swap文件以"提升"内存容量 ➜ ~ sudo dd if=/dev/zero of=/swapfile bs=1024 count=500000 ➜ ~ sudo mkswap /swapfile ➜ ~ sudo chown root:root /swapfile ➜ ~ sudo chmod 0600 /swapfile ➜ ~ sudo swapon /swapfile #查看"提升"后的效果 ➜ ~ free -m ➜ ~ swapon -s #重新用PIP安装lxml ➜ ~ CFLAGS="-O0" sudo /usr/local/bin/pip install lxml
&
#!/bin/bash # set -x set -e export PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin/:/usr/local/sbin #查看磁盘和swap的使用情况 date && df -h date && free -m swapon -s #用多余的磁盘空间创建swap文件以"提升"内存容量 sudo dd if=/dev/zero of=/swapfile bs=1024 count=500000 sudo mkswap /swapfile sudo chown root:root /swapfile sudo chmod 0600 /swapfile sudo swapon /swapfile #查看"提升"后的效果 date && df -h date && free -m swapon -s #将配置写入fstab文件,使重启后依然生效 echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab
参考链接:
- https://www.wordspeak.org/posts/resolving-build-errors-with-python-lxml.html
- http://stackoverflow.com/questions/18334366/out-of-memory-issue-in-installing-packages-on-ubuntu-server
- https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
- https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-6
- http://stackoverflow.com/questions/16149613/installing-lxml-with-pip-in-virtualenv-ubuntu-12-10-error-command-gcc-failed
- http://lxml.de/installation.html
- http://www.cnblogs.com/LubinLew/p/Linux_SwapSpace.html
=END=
《 “在小内存机器上安装lxml” 》 有 4 条评论
在Linux系统上如何升级以保证安全?
https://www.digitalocean.com/community/tutorials/how-to-protect-your-server-against-the-dirty-cow-linux-vulnerability
`
# Ubuntu
$ sudo apt-get update && sudo apt-get dist-upgrade
$ sudo reboot
# CentOS/RHEL
$ sudo yum update
$ sudo reboot
`
All about Linux swap space (关于Linux上swap空间的一切)
https://www.linux.com/news/all-about-linux-swap-space
如何查询Linux服务器上 swap 的占用情况
https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/
https://www.cyberciti.biz/faq/linux-check-swap-usage-command/
`
# swapon –summary
# cat /proc/swaps
# free -h
# top #其中以’KiB Swap:’开头的那一行(第5行)
# atop/htop/glances
`
Linux下如何具体定位是哪个进程在使用 swap 空间?
https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
`
$ ps aux | grep python
$ pgrep python
$ grep –color VmSwap /proc/$pid/status
# 对机器上占用swap空间的进程按照占用情况进行排序
# for file in /proc/*/status ; do awk ‘/VmSwap|Name/{printf $2 ” ” $3}END{ print “”}’ $file; done | sort -k 2 -n -r | less
`