Swap memory
(Straight out of http://stackoverflow.com/questions/20111242/how-to-avoid-errno-12-cannot-allocate-memory-errors-caused-by-using-subprocess)
If you are running out of memory, you may want to increase your swap memory. Or you might have no swap enabled at all. In Ubuntu (it should work for other distributions as well) you can check your swap by:
$ sudo swapon -s
if it is empty it means you don’t have any swap enabled. To add a 8GB swap:
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
Add the following line to the fstab
to make the swap permanent.
$ sudo nano/etc/fstab/swapfile none swap sw 0 0
Removing Swap memory
$ sudo swapoff /swapfile
$ sudo rm /swapfile
Clear Swap & free memory
$ sudo swapoff -a && sudo swapon -a
$ sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"
$ free -h
For Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04