When we can't use a binary package of TensorFlow, we have to compile and install it from source.
For Ubuntu and CPU only
In usual, we can use pre-built TensorFlow packages for Linux and macOS systems. Sometimes even the package was successfully installed, we couldn't run it. Then you should check your processor type. For example, in our case, a model name of processor is "Common KVM processor" which is used in VM environment. |
$ sudo apt install python-dev python-pip $ pip install -U --user pip six numpy wheel setuptools mock $ pip install -U --user keras_applications==1.0.6 --no-deps $ pip install -U --user keras_preprocessing==1.0.5 --no-deps |
If 'pip' is not working even there's no installation error, you can use 'python -m pip' instead of 'pip.' |
$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python |
Next, download the Bazel binary installer named bazel-<version>-installer-linux-x86_64.sh
from the Bazel releases page on GitHub.
$ chmod +x bazel-0.25.2-installer-linux-x86_64.sh $ ./bazel-0.25.2-installer-linux-x86_64.sh --user |
The Bazel executable is installed in your $HOME/bin directory.
$ export PATH="$PATH:$HOME/bin" |
You can also add the command to your ~/.bashrc file.
# Download the source code $ git clone https://github.com/tensorflow/tensorflow.git $ cd tensorflow # Configure the build $ ./configure # Bazel build (Take a long time) $ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package # Build the package $ ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg # Install the package $ pip install /tmp/tensorflow_pkg/tensorflow-1.13.1-cp27-cp27mu-linux_x86_64.whl |
If you get the error related to 'tpu.TPUConfig' import, you need to update tensorflow estimator from source as well.
# Download tensorflow estimator $ git clone https://github.com/tensorflow/estimator.git $ cd estimator # Bazel build and install $ bazel build //tensorflow_estimator/tools/pip_package:build_pip_package $ bazel-bin/tensorflow_estimator/tools/pip_package/build_pip_package /tmp/estimator_pip $ pip install /tmp/estimator_pip/tensorflow_estimator-1.14.0-py2.py3-none-any.whl |