## TensorFlow from source

“This should be easy” = Famous last words… We’ll see.

I used this very helpful guide but with the following differences :

• This was a laptop install, so no GPU required
• The gcc version issues discussed in the helpful guide above are really a CUDA problem.
• Since I use the negativo Nvidia repo to deal with this, these compilation tweaks would have already been taken care of if I were using a GPU
• Anaconda didn’t seem necessary

### Prepare the system packages

As root :

### Prepare user-land set-up

#### bazel installation

As a regular user :

#### Download tensorflow

As a regular user :

### Build tensorflow

This needs several preparatory steps :

• Create a virtualenv so that Python knows which version it’s building for
• Set up the defaults correctly (some CLI interaction)
• Build a pip package with bazel (iterate to fix the problems…)
• Install the pip package

#### Set up Python : python-3.6 virtualenv

I did this in the repo base directory itself. That may have been an unhelpful choice, since (later) I found that I couldn’t use import tensorflow there, since the repo itself has a tensorflow/__init__.py which seems to take priority. OTOH, this doesn’t stop me using the newly built tensorflow anywhere else…

#### ./configure machine compilation defaults

(All default options apart from adding XLA support) :

#### bazel build the pip package (builds tensorflow too)

This took over an hour (even when it worked cleanly) :

Magic fix hints:

Finally iterate to the following (working) command line :

A second bazel build takes 9 seconds to figure out that nothing needs to be recompiled.

A third bazel build takes 0.5 seconds to figure out that nothing needs to be recompiled.

#### Build the pip whl package itself

This creates the ‘wheel’ in /tmp/tensorflow_pkg, and then installs it into the env3 :

### Test the install

You need to use the env3 with the freshly built tensorflow inside it, but then move to a directory other than the base repo, since that includes a ‘distracting’ tensorflow/__init__.py file. Then, run python to get a python prompt, and :

should give you results (slightly reformatted) :

All Done!