Trouble installing scipy in virtualenv on a amazon ec2 linux micro instance

One solution is to temporarily enable swap on your micro instance. As described at this SO post, enable 1gb swap via:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

Once swap is on, install scipy via pip:

sudo apt-get install -y libatlas-base-dev gfortran python-dev build-essential g++
sudo pip install numpy
sudo pip install scipy

Once scipy successfully installs, you can disable it via:

sudo swapoff /var/swap.1
sudo rm /var/swap.1

This worked for me:

pip --no-cache-dir install scipy

See:

  • Memory error while using pip install Matplotlib

    https://github.com/pypa/pip/blob/9a23d4ed119327d3b823ec223aaead90964bac58/pip/basecommand.py#L56-L63

  • https://github.com/pypa/pip/blob/28cca11e284b37cc2c7977fd25be6f494adda9d3/src/pip/_internal/download.py#L359-L367

note:

  • works for other service providers, hardware, VMs, and containers.
  • if RAM allocation size of 1GB
  • just calculate the diff between the cached directory memory usage and available ram