π 2019-Apr-25 ⬩ βοΈ Ashwin Nanjappa ⬩ π·οΈ tensorflow ⬩ π Archive
TensorFlow (TF) can be built from source easily and installed as a Python wheel package. I used the following steps to build it using Python3 and with support for CUDA and TensorRT:
$ sudo apt install python3-dev python3-pip
$ pip3 install -U --user six numpy wheel setuptools mock
$ pip3 install -U --user keras_applications==1.0.6 --no-deps
$ pip3 install -U --user keras_preprocessing==1.0.5 --no-deps
These packages are installed to your ~/.local/lib/python3.x/site-packages
directory. TF documentation also installs the latest pip3 from PyPI. However, doing that causes the infamous βCannot import name mainβ error, so I do not do that.
TF uses Bazel as its build tool. Install it as described here. I ended up placing its binary in my ~/bin
. Since my ~/bin
is in my PATH
, the Bazel binary can be executed from any place.
I recommend creating a tensorflow_root
directory. This is because the TF packaging tends to write out to a location outside the TF source directory. Also, TF needs to access other libraries. So this root directory makes it easy to create all TF related directories under one umbrella.
Clone the TF Git repository inside the root directory:
$ cd tensorflow_root
$ git clone git@github.com:tensorflow/tensorflow.git
$ cd tensorflow
$ ./configure
Some of the questions it asks and my replies:
Please specify the location of python. /usr/bin/python3
Please input the desired Python library path to use. /usr/local/lib/python3.6/dist-packages
Enable: XLA JIT, CUDA and TensorRT. Be careful, TF might not work with latest versions of CUDA, cuDNN and TensorRT. I used CUDA 10.0 and cuDNN 7.3 and TensorRT 5.0.
Did not enable: OpenCL SYCL and ROCm.
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
The first build can take 2-4 hours to complete.
$ ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /path_to_tensorflow_root/tensorflow_pkg
I found that it had generated a Python wheel file named: tensorflow-1.13.1-cp36-cp36m-linux_x86_64.whl
$ pip3 uninstall tensorflow tensorflow-estimator
$ pip3 install -U --user tensorflow-1.13.1-cp36-cp36m-linux_x86_64.whl
$ python3 -c "import tensorflow"
Tried with: Tensorflow 1.13.1 and Ubuntu 18.04