Search code examples
tensorflowbuildbazel

Troubles with bazel and building tensorflow on ubuntu


I'm trying to build tensorflow on ubuntu using bazel, I failed using bazelisk and bazel. There is some silly bug with the installer. I'm really having hard time because of the awful documentation of building tensorflow from source found here

wget https://github.com/bazelbuild/bazel/releases/download/0.27.1/bazel-0.27.1-installer-linux-x86_64.sh
chmod +x bazel-0.27.1-installer-linux-x86_64.sh 
./bazel-0.27.1-installer-linux-x86_64.sh --user
export PATH="$PATH:$HOME/bin"
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
./configure

Out:

INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=80
INFO: Reading rc options for 'version' from /home/emadboctor/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
ERROR: Unrecognized option: --experimental_repo_remote_exec
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Traceback (most recent call last):
  File "./configure.py", line 1553, in <module>
    main()
  File "./configure.py", line 1370, in main
    _TF_MAX_BAZEL_VERSION)
  File "./configure.py", line 485, in check_bazel_version
    ['bazel', '--batch', '--bazelrc=/dev/null', 'version'])
  File "./configure.py", line 161, in run_shell
    output = subprocess.check_output(cmd, stderr=stderr)
  File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bazel', '--batch', '--bazelrc=/dev/null', 'version']' returned non-zero exit status 2

And this keeps happening with version 0.25.1 and 0.19.1

and when I try this version of installation:

sudo apt install curl
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo apt update && sudo apt install bazel
sudo apt update && sudo apt full-upgrade
sudo apt install bazel-1.0.0
cd tensorflow 
./configure

This issue comes up:

Traceback (most recent call last):
  File "./configure.py", line 1553, in <module>
    main()
  File "./configure.py", line 1370, in main
    _TF_MAX_BAZEL_VERSION)
  File "./configure.py", line 485, in check_bazel_version
    ['bazel', '--batch', '--bazelrc=/dev/null', 'version'])
  File "./configure.py", line 161, in run_shell
    output = subprocess.check_output(cmd, stderr=stderr)
  File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bazel', '--batch', '--bazelrc=/dev/null', 'version']' returned non-zero exit status 1

So I try following the guide found here

sudo apt update
sudo apt dist-upgrade
sudo apt install git openjdk-8-jdk curl
sudo apt install python3-dev python3-pip python3-numpy
sudo apt install pkg-config zip g++ zlib1g-dev unzip
wget https://github.com/bazelbuild/bazel/releases/download/0.19.2/bazel-0.19.2-installer-linux-x86_64.sh
chmod +x bazel-0.19.2-installer-linux-x86_64.sh
sudo ./bazel-0.19.2-installer-linux-x86_64.sh
sudo swapoff /swapfile
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout r2.1

Same error as before:

Extracting Bazel installation...
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=80
INFO: Reading rc options for 'version' from /home/emadboctor/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
ERROR: Unrecognized option: --experimental_repo_remote_exec
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Traceback (most recent call last):
  File "./configure.py", line 1553, in <module>
    main()
  File "./configure.py", line 1370, in main
    _TF_MAX_BAZEL_VERSION)
  File "./configure.py", line 485, in check_bazel_version
    ['bazel', '--batch', '--bazelrc=/dev/null', 'version'])
  File "./configure.py", line 161, in run_shell
    output = subprocess.check_output(cmd, stderr=stderr)
  File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bazel', '--batch', '--bazelrc=/dev/null', 'version']' returned non-zero exit status 2

so I try bazelisk(and this is supposed to install the correct version of bazel):

Here are the exact steps:

sudo apt-get update && sudo apt-get upgrade
sudo apt install python-dev python-pip  # or python3-dev python3-pip
pip install -U --user pip six numpy wheel setuptools mock 'future>=0.17.1'
pip install -U --user keras_applications --no-deps
pip install -U --user keras_preprocessing --no-deps

then I install go using this

cd /tmp
wget https://dl.google.com/go/go1.11.linux-amd64.tar.gz
sudo tar -xvf go1.11.linux-amd64.tar.gz
sudo mv go /usr/local
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
source ~/.profile

Then I install bazelisk using this

go get github.com/bazelbuild/bazelisk
export PATH=$PATH:$(go env GOPATH)/bin

then I try to configure again:

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
./configure

Out:

Extracting Bazel installation...
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=80
INFO: Reading rc options for 'version' from /tmp/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
ERROR: Unrecognized option: --experimental_repo_remote_exec
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Traceback (most recent call last):
  File "./configure.py", line 1553, in <module>
    main()
  File "./configure.py", line 1370, in main
    _TF_MAX_BAZEL_VERSION)
  File "./configure.py", line 485, in check_bazel_version
    ['bazel', '--batch', '--bazelrc=/dev/null', 'version'])
  File "./configure.py", line 161, in run_shell
    output = subprocess.check_output(cmd, stderr=stderr)
  File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bazel', '--batch', '--bazelrc=/dev/null', 'version']' returned non-zero exit status 2

Then I retry this, I get new error:

Extracting Bazel installation...
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.19.2 installed.
Please upgrade your bazel installation to version 0.27.1 or higher to build TensorFlow!

So I install 0.27.1 in the following way:

wget https://github.com/bazelbuild/bazel/releases/download/0.27.1/bazel-0.27.1-installer-linux-x86_64.sh
chmod +x bazel-0.27.1-installer-linux-x86_64.sh
./bazel-0.27.1-installer-linux-x86_64.sh --user
export PATH="$PATH:$HOME/bin"
cd tensorflow
./configure

I get the same error even after installing the required version

WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.19.2 installed.
Please upgrade your bazel installation to version 0.27.1 or higher to build TensorFlow!

and this is the output of bazel version:

Starting local Bazel server and connecting to it...
Build label: 0.19.2
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Nov 19 16:25:09 2018 (1542644709)
Build timestamp: 1542644709
Build timestamp as int: 1542644709

Solution

  • Your checkout of the Tensorflow source code requires Bazel 2.0.0, because of the use of the --experimental_repo_remote_exec flag.

    Also see https://github.com/tensorflow/tensorflow/issues/37474

    You almost got it right with bazelisk. go get github.com/bazelbuild/bazelisk installs bazelisk as bazelisk. Instead, download bazelisk, and create a symlink at ~/bin/bazel to point to bazelisk. This way, TensorFlow's configure script can successfully pick up bazelisk as bazel.

    go get github.com/bazelbuild/bazelisk
    mkdir -p ~/bin
    ln -s $(go env GOPATH)/bin/bazelisk ~/bin/bazel
    export PATH=$HOME/bin:$PATH