2021-01-11 Build Tensorflow from source

Tensorflow has no released for python 3.9 yet. To build it from source, bazel must be installed first.

curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
apt update
apt install bazel
bazel --version

Then Tensorflow:

pip install keras_preprocessing --no-deps
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
./configure

The last script prompts to ask question. One of them is the CPU optimization. Nothing or some suggestions:

--copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2

Then build tensorflow:

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

And finally:

bazel-bin/tensorflow/tools/pip_package/build_pip_package --nightly_flag tensorflow_pkg

It took me 5 to 6 hours to build the whole package. Then pip install ….