Tensorflow compiling from source failed on Amazon Ubuntu

RoboForex – Professional services on Forex market

Reference Links:



To compile tensorflow on my Amazon AWS server, I always get some strange error. No answer got upon enormous googling.

I installed swig which is needed. However, I don’t know if this matters.

sudo apt install swig

Otherwise, maybe it just a simple running out of memory problem.

Try reducing number of parallel builds by passing ‘–local_resources 2048,.5,1.0’, which would instruct bazel to spawn no more than one compiler process at the time.

bazel build -c opt --jobs 1 --local_resources 2048,0.5,1.0 --verbose_failures --config=cuda //tensorflow/tools/pip_package:build_pip_package

And I added a swap file:


  • Create a swap file, this method is relatively slow.
sudo dd if=/dev/zero of=/swapfile bs=1G count=4


sudo fallocate -l 4G /swapfile
  • Change the mode of the swap file.
  • Activate the swap file.
  • Mount the swap file.
sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

If you want to use this swap file on boot, append this on /etc/fstab file:

/swapfile none swap sw 0 0


Leave a Reply