I recently needed to install tensorflow on an Intel NUC, which for a number of esoteric reasons was constrained to be running 32-bit Ubuntu 16.04. Unfortunately, the only tensorflow binaries provided by Google are for 64-bit operating systems, so I decided to compile tensorflow from source. I mainly relied on this very useful blog post to get started, but I had to do a few time-consuming tweaks, which I’m outlining here in case anyone finds them useful:
sudo apt-get install openjdk-8-jdk
sudo apt-get install git zip unzip autoconf automake libtool curl zlib1g-dev git clone https://github.com/google/protobuf.git cd protobuf git checkout tags/v3.0.0 ./autogen.sh ./configure --prefix=/usr make -j 4 sudo make install sudo apt-get install maven cd java mvn package cd ../..
git clone https://github.com/grpc/grpc-java.git cd grpc-java git checkout tags/v0.15.0 cd compiler ../gradlew java_pluginExecutable cd ../..
Instead of version 0.1.0 of bazel, which the original blog post recommends, I checked out version 0.3.2 because it the older version lead to errors during tensorflow 0.12.0-rc0 compilation.
git clone https://github.com/bazelbuild/bazel.git cd bazel git checkout tags/0.3.2 sudo cp /usr/bin/protoc third_party/protobuf/protoc-linux-x86_32.exe sudo cp ../protobuf/java/core/target/protobuf-java-3.0.0.jar \ third_party/protobuf/protobuf-java-3.0.0-beta-1.jar sudo cp ../grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java \ third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_32.exe sudo ./compile.sh sudo cp output/bazel /usr/local/bin/bazel cd ..
You might get asked to set PROTOC and GRPC_JAVA_PLUGIN environment variables at some point in this process. In my case I had to do
export PROTOC=protoc export GRPC_JAVA_PLUGIN= path/to/grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java
sudo apt-get install python-numpy swig python-dev git clone https://github.com/tensorflow/tensorflow.git cd tensorflow git checkout tags/0.12.0-rc0 sudo ./configure sudo bazel build -c opt --local_resources 2048,0.5,1.0 \ --verbose_failures //tensorflow/tools/pip_package:build_pip_package (This will take > 30mins. Go for a coffee) sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip install /tmp/tensorflow_pkg/tensorflow-[some version here]-py2-none-any.whl
I suppose that Google is going to also offer support for 32-bit binaries at some point, but until then, I hope this is useful.