How to install Tensorflow GPU with CUDA Toolkit 9.1 and cuDNN 7.1.2 for Python 3 on Ubuntu 16.04-64bit

STEP BY STEP INSTALLATION OF CUDA TOOLKIT 9.1, CUDNN 7.0.5 AND TENSORFLOW 1.4.1 GPU VERSION ON UBUNTU 16.04

This is going to be a tutorial on how to install tensorflow 1.7.0 GPU version. We will also be installing CUDA Toolkit 9.1 and cuDNN 7.1.2 along with the GPU version of tensorflow 1.7.0. At the time of writing this blog post, the latest version of tensorflow is 1.7.0.This tutorial is for building tensorflow from source. If you want to use the official pre-built pip package instead, I recommend another post, How to install Tensorflow 1.7.0 using official pip package.

Tensorflow is an open source software library developed and used by Google that is fairly common among students, researchers, and developers for deep learning applications such as neural networks. It has both the CPU as well as GPU version available and although the CPU version works quite well, realistically, if you are going for deep learning, you will need GPU. In order to use the GPU version of TensorFlow, you will need an NVIDIA GPU with a compute capability > 3.0. While it is technically possible to install tensorflow GPU version in a virtual machine, you cannot access the full power of your GPU via a virtual machine. So, I recommend doing a fresh install of Ubuntu if you don’t have Ubuntu before starting with the tutorial.

There must be 64-bit python installed tensorflow does not work on 32-bit python installation.

Step 1: Update and Upgrade your system:

sudo apt-get update 
sudo apt-get upgrade

Step 2: Verify You Have a CUDA-Capable GPU:

lspci | grep -i nvidia

Note GPU model. eg. GeForce 840M

If you do not see any settings, update the PCI hardware database that Linux maintains by entering update-pciids (generally found in /sbin) at the command line and rerun the previous lspci command.

If your graphics card is from NVIDIA then goto http://developer.nvidia.com/cuda-gpus and verify if listed in CUDA enabled gpu list.

Note down its Compute Capability. eg. GeForce 840M 5.0

Step 3: Verify You Have a Supported Version of Linux:

To determine which distribution and release number you’re running, type the following at the command line:

uname -m && cat /etc/*release

The x86_64 line indicates you are running on a 64-bit system which is supported by cuda 9.1

Step 4: Install Dependencies:

Required to compile from source:

sudo apt-get install build-essential 
sudo apt-get install cmake git unzip zip 
sudo apt-get install python2.7-dev python3.5-dev python3.6-dev pylint

Step 5: Install linux kernel header:

Goto terminal and type:

uname -r

You can get like “4.10.0-42-generic”. Note down linux kernel version.

To install linux header supported by your linux kernel do following:

sudo apt-get install linux-headers-$(uname -r)

Step 6:  Download the NVIDIA CUDA Toolkit:

Go to https://developer.nvidia.com/cuda-downloads and download Installer for Linux Ubuntu 16.04 x86_64 deb[network]. I highly recommend network installer to get updated gpu driver supported by your linux kernel.

For, direct download

wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

Installation Instructions:

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda-9.1

Step 7: Reboot the system to load the NVIDIA drivers.

Step 8: Go to terminal and type:

nano ~/.bashrc

In the end of the file, add:

export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

ctrl+x then y to save and exit

source ~/.bashrc
sudo ldconfig
nvidia-smi

Check driver version probably Driver Version: 390.30

(not likely) If you got nvidia-smi is not found then you have unsupported linux kernel installed. Comment your linux kernel version noted in step 5.

Step 9: Install cuDNN 7.1.2:

Goto https://developer.nvidia.com/cudnn and download Membership required

After login

Download the following:

cuDNN v7.1.2 Runtime Library for Ubuntu16.04 (Deb)

cuDNN v7.1.2 Developer Library for Ubuntu16.04 (Deb)

cuDNN v7.1.2 Code Samples and User Guide for Ubuntu16.04 (Deb)

Goto downloaded folder and in terminal perform following:

sudo dpkg -i libcudnn7_7.1.2.21-1+cuda9.1_amd64.deb
sudo dpkg -i libcudnn7-dev_7.1.2.21-1+cuda9.1_amd64.deb
sudo dpkg -i libcudnn7-doc_7.1.2.21-1+cuda9.1_amd64.deb

Verifying cuDNN installation:

cp -r /usr/src/cudnn_samples_v7/ $HOME
cd  $HOME/cudnn_samples_v7/mnistCUDNN
make clean && make
./mnistCUDNN

If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:

Test passed!

Step 10: Install Dependencies

libcupti (required)

sudo apt-get install libcupti-dev
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

Bazel (required)

sudo apt-get install openjdk-8-jdk
wget https://github.com/bazelbuild/bazel/releases/download/0.11.1/bazel_0.11.1-linux-x86_64.deb
sudo dpkg -i bazel_0.11.1-linux-x86_64.deb

To install these packages for Python 2.7, issue the following command:

sudo apt-get install python-numpy python-dev python-pip python-wheel

To install these packages for Python 3.n, issue the following command:

sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel

Step 11: Configure Tensorflow from source:

Reload environment variables

source ~/.bashrc
sudo ldconfig

Start the process of building TensorFlow by downloading latest tensorflow 1.7.0 .

wget https://github.com/tensorflow/tensorflow/archive/v1.7.0.zip
unzip v1.7.0.zip
cd tensorflow-1.7.0
./configure

Give python path in

Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3

Press enter two times

Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: Y
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: Y
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: Y
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: Y
Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: N
Do you wish to build TensorFlow with XLA JIT support? [y/N]: N
Do you wish to build TensorFlow with GDR support? [y/N]: N
Do you wish to build TensorFlow with VERBS support? [y/N]: N
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N
Do you wish to build TensorFlow with CUDA support? [y/N]: Y
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 9.0]: 9.1
Please specify the location where CUDA 9.1 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.1.2
Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/lib/x86_64-linux-gnu
Do you wish to build TensorFlow with TensorRT support? [y/N]: N

Now we need compute capability which we have noted at step 1 eg. 5.0

Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 5.0] 5.0
Do you want to use clang as CUDA compiler? [y/N]: N
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc
Do you wish to build TensorFlow with MPI support? [y/N]: N
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:N

Configuration finished

Step 12: Build Tensorflow using bazel

Do following to create symbolic link to cuda/include/math_functions.hpp from cuda/include/crt/math_functions.hpp to fix math_functions.hpp is not found error.

sudo ln -s /usr/local/cuda/include/crt/math_functions.hpp /usr/local/cuda/include/math_functions.hpp

If it says file already exits then ignore it.

The next step in the process to install tensorflow GPU version will be to build tensorflow using bazel. This process takes a fairly long time.

To build a pip package for TensorFlow with CPU-only support, you would typically invoke the following command:

bazel build --config=opt --incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package

Note:-

 add "--config=mkl" if you want Intel MKL support for newer intel cpu for faster training on cpu

We are building with GPU support so do following

To build a pip package for TensorFlow with GPU support, invoke the following command:

bazel build --config=opt --config=cuda --incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package

This process will take a lot of time. It may take 1 – 2 hours or maybe even more.

The bazel build command builds a script named build_pip_package. Running this script as follows will build a .whl file within the tensorflow_pkg directory:

To build whl file issue following command:

bazel-bin/tensorflow/tools/pip_package/build_pip_package tensorflow_pkg

Activate your virtual environment here if you use.

To install tensorflow with pip:

cd tensorflow_pkg

for python 2:

pip2 install tensorflow*.whl

for python 3:

pip3 install tensorflow*.whl

Step 13: Verify Tensorflow installation

Run in terminal

python

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!

Success! You have now successfully installed tensorflow 1.7.0 on your machine. If you are on Windows OS, you might want to check out our other post here, How to install Tensorflow 1.7.0 GPU with CUDA Toolkit 9.1 and cuDNN 7.1.2 for Python 3 on Windows OS. Cheers!!

For prebuilt wheel with optimization for AVX2 and cuda 9.1, cudnn 7.1.2, compute capability 5.0 go to this link .

 

109 Comments on How to install Tensorflow GPU with CUDA Toolkit 9.1 and cuDNN 7.1.2 for Python 3 on Ubuntu 16.04-64bit

  1. sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb
    sudo dpkg -i libcudnn7-dev_7.0.3.11-1+cuda9.0_amd64.deb
    sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb

    this are cuda9.0 version
    i think they must be cuda9.1 version !!!

    • Hello naser,

      Thank you for the comment. It seems there has been a slight mistake on the post and now it’s updated.

      Cheers!

    • Hello Benoit Courty. Thank you for your valuable comment. If CUDA Toolkit is installed correctly then all symbolic links should be generated in /usr/local/cuda.
      However, in cases where the symbolic links are not automatically created, you will get an error saying “math_functions.hpp: No such file or directory”. Creating a symlink from cuda/include/math_functions.hpp to cuda/include/crt/math_functions.hpp fixes the issue as you suggested.

  2. Hi.After building the tensorflow file and changing the directory to tensorflow_package, i am getting the following error-Double requirement given: tensorflow==1.4.1 from file:///home/dhruv/tensorflow-1.4.1/tensorflow_pkg/tensorflow-1.4.1-cp36-cp36m-linux_x86_64.whl (already in tensorflow, name=’tensorflow’)

    How do i resolve this error?

    • I think pip install –upgrade tensorflow*.whl should work. If not worked then this might work pip install –upgrade –no-deps –force-reinstall tensorflow*.whl
      Reply me if any issue.

  3. I have successfully followed the above on Ubuntu 17.04 with the following changes:
    changed the all references to ubuntu1604 in step 6 to ubuntu 1704
    to build bazel for cuda 9.1 in step 12 I needed ‘sudo ln -s /usr/local/cuda/include/crt/math_functions.hpp /usr/local/cuda/include/math_functions.hpp’ as other have pointed out.
    I needed to use ‘pip3 install tensorflow*’ at the end of step 12 else I got ‘xxx.whl is not a supported wheel on this platform’.
    Thanks so much for this tutorial – it has enabled me to get tensorflow working on my GPU after a couple of days of trying to get various versions of ubuntu, cuda, tensorflow all playing happy in the same box – can finally get on with the Udacity Deep Learning course

  4. bazel build –config=opt –-config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package

    It seems there is incorrect symbol, “–” instead of “-” before config=cuda. Not sure if this matters but at the moment I’ve got that tensorflow was built without CUDA support so I’m rebuilding it.

    • Thank you, Dmitry. It happened due to auto-correct option of editor. Now updated. There is two command CPU only and GPU support. I hope you have used GPU version command for bazel. Have you configured to build CUDA (Y) in while running ./configure ?

  5. i did every step as mentioned but I am getting this error

    after using pip install tensorflow*

    tensorflow-1.4.1-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.

    • Thank you for comment. You have built tensorflow with python 2.7 version. I have not tested on 2.7. Does pip belongs to python 27? You can check by pip –version. I think pip2 install tensorflo*.whl should work.

      • I have a similar problem

        tensorflow-1.4.1-cp35-cp35m-linux_x86_64.whl is not a supported wheel on this platform.

        • Please check the python version and associated pip command. The wheel you are trying to install is for python 3.5 64 bit.

  6. I’ve installed correctly tensorflow with GPU’s, but i can’t run it with other users, i have the next error:

    ImportError: No module named ‘tensorflow’

    what should i do ?

    • Does it worked on current user? For another user pip install tensorflow*.whl should work. It will be good to use virtualenv.

  7. I’m sorry can you please elaborate on step 5? Why is this step needed? The output from “uname -r” for me was 4.10.0-28-generic. Does that mean I can skip this step bc it’s 4.10?

  8. Thanks. I’m having an issue installing Cuda Toolkit 9.1 on my clean install of ubuntu 16.04

    After installing, on reboot, I get stuck in an endless loop of: 1. login screen – 2. enter credentials – 3. crash – 1.login screen..

    Video: https://youtu.be/da1Xv7mNwrQ

    For anyone else having issues, I found another person with the same problem and we’ve been discussing on this thread:

    https://devtalk.nvidia.com/default/topic/1028802/problems-with-cuda-9-1-in-ubuntu-16-04/?offset=9#5233925

    • Thanks Patrick. If followed steps carefully then there should not be problem. Please check your linux kernel version and run deb network installer as written in tutorial.

  9. Arun,

    This article is incredibly detailed and obviously took a lot of time to put together. Thanks for the effort.

    I’m attempting to follow your instructions, but am utterly baffled by what I’m supposed to do in Step 5. The ‘uname -r’ command on my machine returns 4.13.0-1007-gcp.

    As suggested, I ran the remove command and rebooted my machine (a Google Cloud VM). Now the machine is effectively dead (no surprise here). I can delete and recreate the VM, but I still don’t know how to correctly remove and install the correct version of the kernel.

    Tx.

    Joe

    • Hi Joe. I think you have only linux kernel 4.13 installed and removing it makes ubuntu unbootable. I have updated the tutorial. May be latest nvidia driver works on latest kernel. But only use cuda toolkit deb network installer to get latest nvidia driver. If it not worked then you can install linux image 4.10 and its headers first before removing 4.13.

  10. Thank you for taking the time to create this. It (so far) has been very helpful. I have been struggling for days to get everything to work, despite following all the appropriate guides and all the install manuals. It seems like I tried to install when all the release cycles didn’t correspond.

    My question is: If I wanted to uninstall this in the future, how would I go about doing that? Would it be as simple as pip uninstall tensorflow?

    • Hi Andrew. By going through tutorial you have installed cuda 9.1 and latest nvidia gpu driver and built tensorflow-gpu whl file. To uninstall tensorflow only not cuda 9.1 then pip uninstall works. But if you want to install official prebuilt whl file then you need cuda 9.0. In that case you have to uninstall cuda 9.1 too and then install cuda 9.0.

  11. Hello. WOnderful post. I’m unable to build tensorflow due to my gcc version being above 6. How do I fix this?

    • Hello, sudo apt-get install build-essential should install gcc 5.4 on ubuntu 16.04. Then you can create symbolic link for gcc5.4 to gcc in /usr/bin using
      ln -s /usr/bin/g++-6 /usr/bin/g++
      ln -s /usr/bin/gcc-6 /usr/bin/gcc

  12. Hi. when in Step12 after “bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package” I got 2 Errors:
    a)ERROR: /home/stacey/tensorflow-1.4.1/tensorflow/contrib/s3/BUILD:69:1: no such package ‘@aws//’: java.io.IOException: thread interrupted and referenced by ‘//tensorflow/contrib/s3:s3_file_system’
    b)ERROR: Analysis of target ‘//tensorflow/tools/pip_package:build_pip_package’ failed; build aborted: no such package ‘@aws//’: java.io.IOException: thread interrupted
    I’m new in this platform and have no idea with that, could anyone help? Thanks a lot!

    • What is your build platform and OS ? Please make sure patch is installed. If not installed then installed from apt (or yum). Then do this before ./configure “bazel clean –expunge” and then “bazel shutdown”.

      • Wow! Thanks for your quick reply! I followed your suggestions and now I saw “Hello, Tensorflow!” 😀

    • Thanks for sharing. It will be useful to others to in case of build error related to so file reference. Did you define LD_LIBRARY_PATH in bashrc as mentioned in step 8 ?

  13. Compiling TF 1.5.0 from source is extermely differnet than 1.4.1

    it does not download MKL if you need it so you need to give it the MKL_ROOT folder
    it forces for some odd reason Andriod SDK to be exist for compilig

    ERROR: /tensorflow/tensorflow/contrib/lite/kernels/internal/BUILD:331:1: no such package ‘@androidndk//’: The repository could not be resolved and referenced by ‘//tensorflow/contrib/lite/kernels/internal:cpu_check’.

    • Hello, according to this file third_party/mkl/build_defs.bzl will download mkl files from internet if not defined locally, i have not tried mkl. Are you trying to build Tensorflow lite ?

  14. I got the following error when I issued:

    “bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package” command:

    ERROR: /home/krish-thorcode/My_files/tensorflow/tensorflow-1.4.1/WORKSPACE:15:1: Traceback (most recent call last):
    File “/home/krish-thorcode/My_files/tensorflow/tensorflow-1.4.1/WORKSPACE”, line 15
    closure_repositories()
    File “/home/krish-thorcode/.cache/bazel/_bazel_krish-thorcode/193a33ded3e9f93a1e2171a9a3a9a41d/external/io_bazel_rules_closure/closure/repositories.bzl”, line 69, in closure_repositories
    _check_bazel_version(“Closure Rules”, “0.4.5”)
    File “/home/krish-thorcode/.cache/bazel/_bazel_krish-thorcode/193a33ded3e9f93a1e2171a9a3a9a41d/external/io_bazel_rules_closure/closure/repositories.bzl”, line 172, in _check_bazel_version
    fail((“%s requires Bazel >=%s but was…)))
    Closure Rules requires Bazel >=0.4.5 but was 0.10.0

  15. hey! thanks for the tut.
    I’m having this error trying to building Tensorflow using bazel:

    cmd :
    bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package

    error:
    Traceback (most recent call last):
    File “”, line 1, in
    ModuleNotFoundError: No module named ‘numpy’
    Is numpy installed?
    and referenced by ‘//util/python:python_headers’
    ERROR: Analysis of target ‘//tensorflow/tools/pip_package:build_pip_package’ failed; build aborted: Loading failed
    INFO: Elapsed time: 1.559s
    FAILED: Build did NOT complete successfully (28 packages loaded)
    currently loading: tensorflow/core … (3 packages)

    but I already have Numpy installed…
    Can you help me please?
    Thanks

    • This tutorial is tested on tensorflow 1.5.0 and please make sure the python defined while running ./configure has numpy installed. You can also give the path of python from a virtual environment which have numpy already installed.

  16. hi thanks for sharing really help a lot. however still i met with a problem :

    when step 12

    bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package

    ———————————————————————
    At global scope:
    cc1plus: warning: unrecognized command line option ‘-Wno-shift-negative-value’
    ERROR: /home/sishuo/.cache/bazel/_bazel_sishuo/331bb7d0079dded51fc30dfe575a62ce/external/farmhash_archive/BUILD:19:1: C++ compilation of rule ‘@farmhash_archive//:farmhash’ failed (Exit 1)
    gcc: error: =: No such file or directory
    gcc: error: native: No such file or directory
    gcc: error: unrecognized command line option ‘-march’
    Target //tensorflow/tools/pip_package:build_pip_package failed to build
    Use –verbose_failures to see the command lines of failed build steps.

    anyone face similar prob?

    • Use verbose_failures and post the error. What version you are using for tensorflow, gcc and bazel ?

        • WARNING: /home/sishuo/Downloads/tensorflow-1.5.0/tensorflow/core/BUILD:1814:1: in includes attribute of cc_library rule //tensorflow/core:framework_headers_lib: ‘../../external/nsync/public’ resolves to ‘external/nsync/public’ not below the relative path of its package ‘tensorflow/core’. This will be an error in the future. Since this rule was created by the macro ‘cc_header_only_library’, the error might have been caused by the macro implementation in /home/sishuo/Downloads/tensorflow-1.5.0/tensorflow/tensorflow.bzl:1138:30
          WARNING: /home/sishuo/Downloads/tensorflow-1.5.0/tensorflow/contrib/learn/BUILD:15:1: in py_library rule //tensorflow/contrib/learn:learn: target ‘//tensorflow/contrib/learn:learn’ depends on deprecated target ‘//tensorflow/contrib/session_bundle:exporter’: No longer supported. Switch to SavedModel immediately.
          WARNING: /home/sishuo/Downloads/tensorflow-1.5.0/tensorflow/contrib/learn/BUILD:15:1: in py_library rule //tensorflow/contrib/learn:learn: target ‘//tensorflow/contrib/learn:learn’ depends on deprecated target ‘//tensorflow/contrib/session_bundle:gc’: No longer supported. Switch to SavedModel immediately.
          INFO: Analysed target //tensorflow/tools/pip_package:build_pip_package (0 packages loaded).
          INFO: Found 1 target…
          ERROR: /home/sishuo/.cache/bazel/_bazel_sishuo/331bb7d0079dded51fc30dfe575a62ce/external/flatbuffers/BUILD:16:1: C++ compilation of rule ‘@flatbuffers//:flatbuffers’ failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command
          (cd /home/sishuo/.cache/bazel/_bazel_sishuo/331bb7d0079dded51fc30dfe575a62ce/execroot/org_tensorflow && \
          exec env – \
          CUDA_TOOLKIT_PATH=/usr/local/cuda \
          CUDNN_INSTALL_PATH=/usr/lib/x86_64-linux-gnu \
          GCC_HOST_COMPILER_PATH=/usr/bin/gcc \
          PWD=/proc/self/cwd \
          PYTHON_BIN_PATH=/usr/bin/python3 \
          PYTHON_LIB_PATH=/usr/local/lib/python3.5/dist-packages \
          TF_CUDA_CLANG=0 \
          TF_CUDA_COMPUTE_CAPABILITIES=6.1 \
          TF_CUDA_VERSION=9.1 \
          TF_CUDNN_VERSION=7.0.5 \
          TF_NEED_CUDA=1 \
          TF_NEED_OPENCL_SYCL=0 \
          external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -U_FORTIFY_SOURCE ‘-D_FORTIFY_SOURCE=1’ -fstack-protector -fPIE -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK -march ‘=’ native ‘-std=c++11’ -MD -MF bazel-out/k8-py3-opt/bin/external/flatbuffers/_objs/flatbuffers/external/flatbuffers/src/reflection.d ‘-frandom-seed=bazel-out/k8-py3-opt/bin/external/flatbuffers/_objs/flatbuffers/external/flatbuffers/src/reflection.o’ -iquote external/flatbuffers -iquote bazel-out/k8-py3-opt/genfiles/external/flatbuffers -iquote external/bazel_tools -iquote bazel-out/k8-py3-opt/genfiles/external/bazel_tools -isystem external/flatbuffers/include -isystem bazel-out/k8-py3-opt/genfiles/external/flatbuffers/include -isystem external/bazel_tools/tools/cpp/gcc3 -fexceptions -Wno-implicit-fallthrough -no-canonical-prefixes -Wno-builtin-macro-redefined ‘-D__DATE__=”redacted”‘ ‘-D__TIMESTAMP__=”redacted”‘ ‘-D__TIME__=”redacted”‘ -fno-canonical-system-headers -c external/flatbuffers/src/reflection.cpp -o bazel-out/k8-py3-opt/bin/external/flatbuffers/_objs/flatbuffers/external/flatbuffers/src/reflection.o)
          gcc: error: =: No such file or directory
          gcc: error: native: No such file or directory
          gcc: error: unrecognized command line option ‘-march’
          Target //tensorflow/tools/pip_package:build_pip_package failed to build

          • use bazel clean --expung then bazel shutdown and start again from ./configure if not worked then remove bazel from cache using following command rm -rf ~/.cache/bazel then try again.

      • ^
        ERROR: /home/sishuo/Downloads/tensorflow-1.5.0/tensorflow/python/BUILD:4585:1: C++ compilation of rule ‘//tensorflow/python:framework/fast_tensor_util.so’ failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command
        (cd /home/sishuo/.cache/bazel/_bazel_sishuo/331bb7d0079dded51fc30dfe575a62ce/execroot/org_tensorflow && \
        exec env – \
        CUDA_TOOLKIT_PATH=/usr/local/cuda \
        CUDNN_INSTALL_PATH=/usr/lib/x86_64-linux-gnu \
        GCC_HOST_COMPILER_PATH=/usr/bin/gcc \
        PWD=/proc/self/cwd \
        PYTHON_BIN_PATH=/usr/bin/python3 \
        PYTHON_LIB_PATH=/usr/local/lib/python3.5/dist-packages \
        TF_CUDA_CLANG=0 \
        TF_CUDA_COMPUTE_CAPABILITIES=6.1 \
        TF_CUDA_VERSION=9.1 \
        TF_CUDNN_VERSION=7.0.5 \
        TF_NEED_CUDA=1 \
        TF_NEED_OPENCL_SYCL=0 \
        external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -U_FORTIFY_SOURCE ‘-D_FORTIFY_SOURCE=1’ -fstack-protector -fPIE -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK -march ‘=’ native ‘-std=c++11’ -MD -MF bazel-out/k8-py3-opt/bin/tensorflow/python/_objs/framework/fast_tensor_util.so/tensorflow/python/framework/fast_tensor_util.pic.d ‘-frandom-seed=bazel-out/k8-py3-opt/bin/tensorflow/python/_objs/framework/fast_tensor_util.so/tensorflow/python/framework/fast_tensor_util.pic.o’ -fPIC -iquote . -iquote bazel-out/k8-py3-opt/genfiles -iquote external/local_config_python -iquote bazel-out/k8-py3-opt/genfiles/external/local_config_python -iquote external/bazel_tools -iquote bazel-out/k8-py3-opt/genfiles/external/bazel_tools -isystem external/local_config_python/numpy_include -isystem bazel-out/k8-py3-opt/genfiles/external/local_config_python/numpy_include -isystem external/bazel_tools/tools/cpp/gcc3 -isystem external/local_config_python/python_include -isystem bazel-out/k8-py3-opt/genfiles/external/local_config_python/python_include -no-canonical-prefixes -Wno-builtin-macro-redefined ‘-D__DATE__=”redacted”‘ ‘-D__TIMESTAMP__=”redacted”‘ ‘-D__TIME__=”redacted”‘ -fno-canonical-system-headers -c bazel-out/k8-py3-opt/genfiles/tensorflow/python/framework/fast_tensor_util.cpp -o bazel-out/k8-py3-opt/bin/tensorflow/python/_objs/framework/fast_tensor_util.so/tensorflow/python/framework/fast_tensor_util.pic.o)
        gcc: error: =: No such file or directory
        gcc: error: native: No such file or directory
        gcc: error: unrecognized command line option ‘-march’
        Target //tensorflow/tools/pip_package:build_pip_package failed to build
        INFO: Elapsed time: 198.452s, Critical Path: 19.14s
        FAILED: Build did NOT complete successfully

            • yes previous reply is after bazel clean and shutdown.
              i tried again with
              bazel clean –expunge
              bazel shutdown

              then re configure following step 11
              then use cpu-ver build comment adding –config=mkl –verbose_failures as below

              bazel build –config=opt –incompatible_load_argument_is_label=false –config=mkl –verbose_failures //tensorflow/tools/pip_package:build_pip_package

              below is full message returned:

              INFO: From ProtoCompile tensorflow/core/example/example.pb.cc:
              bazel-out/k8-py3-opt/genfiles/external/protobuf_archive/src: warning: directory does not exist.
              ERROR: /home/sishuo/Downloads/tensorflow-1.5.0/tensorflow/python/BUILD:1439:1: Linking of rule '//tensorflow/python:gen_spectral_ops_py_wrappers_cc' failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command
              (cd /home/sishuo/.cache/bazel/_bazel_sishuo/331bb7d0079dded51fc30dfe575a62ce/execroot/org_tensorflow && \
              exec env – \
              LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda-9.1/lib64:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda-9.1/lib64 \
              PATH=/usr/local/cuda-9.1/bin:/usr/local/cuda-9.1/bin:/home/sishuo/bin:/home/sishuo/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
              PWD=/proc/self/cwd \
              external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -o bazel-out/host/bin/tensorflow/python/gen_spectral_ops_py_wrappers_cc '-Wl,-rpath,$ORIGIN/../../_solib_local/_U_S_Stensorflow_Spython_Cgen_Uspectral_Uops_Upy_Uwrappers_Ucc___Utensorflow' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../../_solib_local/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uexternal_Smkl_Slib' -Lbazel-out/host/bin/_solib_local/_U_S_Stensorflow_Spython_Cgen_Uspectral_Uops_Upy_Uwrappers_Ucc___Utensorflow -Lbazel-out/host/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/host/bin/_solib_local/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uexternal_Smkl_Slib '-Wl,-rpath,$ORIGIN/,-rpath,$ORIGIN/..' -Wl,-rpath,../local_config_cuda/cuda/lib64 -Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64 -pthread -Wl,-no-as-needed -B/usr/bin/ -pie -Wl,-z,relro,-z,now -no-canonical-prefixes -pass-exit-codes '-Wl,–build-id=md5' '-Wl,–hash-style=gnu' -Wl,–gc-sections -Wl,-S -Wl,@bazel-out/host/bin/tensorflow/python/gen_spectral_ops_py_wrappers_cc-2.params)
              /usr/bin/ld: warning: libnvidia-fatbinaryloader.so.387.26, needed by //usr/lib/x86_64-linux-gnu/libcuda.so.1, not found (try using -rpath or -rpath-link)
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_shnum'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Get_FatBinary_From_Object'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Add_Cubin'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_section_contents'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_section_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `gpuInfoRunsOn'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_section_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf_end'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_named_section_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_shnum'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Delete'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Finish_Reading_Library'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `fatBinaryCtl'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_symbol_shndx'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_typed_section_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `gpucompRestoreLogLine'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_file_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Free_Fatbinary'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_string_at_offset'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_symbol_shndx'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `fatBinaryCtl_Compile'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `fatBinaryCtl_PickCandidate'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_file_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_string_at_offset'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Load_Host_Object'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Start'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Start_Reading_Library'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_typed_section_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Next_Library_Member'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `gpucompSetLogLine'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Finish'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_section_name'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf_is_64bit'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elfLink_Free_Host_Object'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_named_section_header'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf_size'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_symbol_name'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf32_section_name'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `fatBinaryCtl_Delete'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `fatBinaryCtl_Create'
              //usr/lib/x86_64-linux-gnu/libcuda.so.1: undefined reference to `elf64_symbol_name'
              collect2: error: ld returned 1 exit status
              Target //tensorflow/tools/pip_package:build_pip_package failed to build
              INFO: Elapsed time: 320.575s, Critical Path: 28.90s
              FAILED: Build did NOT complete successfully

          • While configuring don’t enable cuda for cpu version and do not use mkl. This is for test build.

            • ah just re install and success

              thank you.
              i think probally i may miss some steps.

              anyway it is solved now. thank you!

  17. Getting this error at STEP-9.previously, I tried to install CUDA 8.0. That was unsuccessful. Currently running Nvidia GForce820M series on my laptop.Please help me if you can…

    cudnnGetVersion() : 7005 , CUDNN_VERSION from cudnn.h : 7005 (7.0.5)
    Host compiler version : GCC 5.4.1
    There are 1 CUDA capable devices on your machine :
    device 0 : sms 2 Capabilities 2.1, SmClock 1250.0 Mhz, MemSize (Mb) 1985, MemClock 900.0 Mhz, Ecc=0, boardGroupID=0
    Using device 0

    Testing single precision
    CUDNN failure
    Error: CUDNN_STATUS_ARCH_MISMATCH
    mnistCUDNN.cpp:394
    Aborting…

    • I think there is miss match between cuda and cudnn, install the appropriate cudnn for cuda you want to choose then configure accordingly. Use network deb installer. If there is error about minimum compute capability then use minimum compute capability it is 3.0 or 3.5. Please confirm that from error.

  18. hi and thx – I got this running before – but was not able to get tensorRT running. It worked only w 9.0/7.0.5
    Did you try this and succeed?

  19. Hello! Great article, I was able to install TensorFlow 1.6 by simply downloading the most recent version and managed to get everything else done following this tutorial.

    However when testing the installation here’s what comes up:

    import tensorflow as tf
    /home/jdevezas/anaconda/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
    from ._conv import register_converters as _register_converters

    hello = tf.constant(‘Hello, TensorFlow!’)

    sess = tf.Session()

    print(sess.run(hello))
    b’Hello, TensorFlow!’

    There’s that message at the beginning and also that ‘b’ before it prints out “Hello, TensorFlow”. Is there anything that can be done? Will it be okay to use TF?

    • You can ignore the warning later it will be resolved. ‘b’ represents bytes type so always include b with string for other use. You can use search engine for clear information. Your installation is good and can continue to use.

  20. Hello thanks a lot for your article
    I can’t make the last step :pip3 install tensorflow*
    I have : tensorflow-1.4.1-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform.

    how can I manage it ?
    thank you

    • Check pip platform pip3 --version the whl is for python 3.6 64 bit python. Use pip associated with python 3.6 64 bit. Thanks.

  21. Hi, thanks a lot for the article. After running the ./configure command and setting the locations I get this error:

    ERROR: /home/mark/.cache/bazel/_bazel_mark/750cb90d9f07da92bb7e9828b438c326/external/io_bazel_rules_closure/closure/private/defs.bzl:27:16: The function ‘set’ has been removed in favor of ‘depset’, please use the latter. You can temporarily refer to the old ‘set’ constructor from unexecuted code by using –incompatible_disallow_uncalled_set_constructor=false
    ERROR: error loading package ”: Extension file ‘closure/private/defs.bzl’ has errors

    Any ideas?

    • According to the error use this argument in bazel build command may fix the error. Use `–incompatible_disallow_uncalled_set_constructor=false`

      • I’ve tried adding it “./configure –incompatible_disallow_uncalled_set_constructor=false” but I get the same error.

        • Add that flag in bazel rather then configure. I can’t test this now but i am planning to update all the tutorials in next week.

          • Sorry I’m still getting the error. I tried running “sudo bazel canonicalize-flags –incompatible_disallow_uncalled_set_constructor=false

            with no errors until ./configure at which point I got the same errors while trying to build. Then I put it in ./configure like so:
            “Please specify optimization flags to use during compilation when bazel option “–config=opt” is specified [Default is -march=native]: –incompatible_disallow_uncalled_set_constructor=false”
            and I also tried putting it after ./configure but all lead to the same error. I’m still kind of a noob to ubuntu so any help is appreciated.

            • Ok. Please specify the os, bazel version, tensorflow and cuda version, gcc version so that i can give you the out of box working solution.

            • I’m on Ubuntu 16.04 , I’ve tried bazel versions 0.1.10(newest one) 0.5.4 and 0.9.0, tensor flow is 1.7.0, CUDA is 9.1 and Cudnn is 7.1.1, and my gcc is 5.4.0

            • Hi Markf, i have tested the build for tensorflow 1.7.0-rc1 with bazel 0.11.1, cuda 9.1, cudnn 7.1.2, gcc 5.4 without any problem. May be there is problem with bazel cache files. so use bazel clean --expung then bazel shutdown and start again from ./configure if not worked then remove bazel from cache using following command rm -rf ~/.cache/bazel then try again. Also use bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package to build.

            • Still no luck after clearing the cache “~/tensorflow$ ./configure
              Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
              Please specify optimization flags to use during compilation when bazel option “–config=opt” is specified [Default is -march=native]:
              Do you wish to use jemalloc as the malloc implementation? [Y/n] y
              jemalloc enabled
              Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] y
              Google Cloud Platform support will be enabled for TensorFlow
              Do you wish to build TensorFlow with Hadoop File System support? [y/N] y
              Hadoop File System support will be enabled for TensorFlow
              Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] n
              No XLA JIT support will be enabled for TensorFlow
              Found possible Python library paths:
              /usr/local/lib/python3.5/dist-packages
              /usr/lib/python3/dist-packages
              Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages]

              Using python library path: /usr/local/lib/python3.5/dist-packages
              Do you wish to build TensorFlow with OpenCL support? [y/N] n
              No OpenCL support will be enabled for TensorFlow
              Do you wish to build TensorFlow with CUDA support? [y/N] y
              CUDA support will be enabled for TensorFlow
              Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
              Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 9.1
              Please specify the location where CUDA 9.1 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
              Please specify the Cudnn version you want to use. [Leave empty to use system default]: 7.1.1
              Please specify the location where cuDNN 7.1.1 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
              Please specify a list of comma-separated Cuda compute capabilities you want to build with.
              You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
              Please note that each additional compute capability significantly increases your build time and binary size.
              [Default is: “3.5,5.2”]: 5.0
              ……….
              INFO: Starting clean (this may take a while). Consider using –async if the clean takes more than several minutes.
              ……….
              ERROR: /home/mark/.cache/bazel/_bazel_mark/750cb90d9f07da92bb7e9828b438c326/external/io_bazel_rules_closure/closure/private/defs.bzl:27:16: The function ‘set’ has been removed in favor of ‘depset’, please use the latter. You can temporarily refer to the old ‘set’ constructor from unexecuted code by using –incompatible_disallow_uncalled_set_constructor=false
              ERROR: error loading package ”: Extension file ‘closure/private/defs.bzl’ has errors
              Building: no action

            • have you deleted the /.cache/bazel dir? using rm -rf ~/.cache/bazel also verify bazel version using ‘bazel version‘. It should be heigher version then 0.10.

            • Upgrade your bazel because tensorflow 1.7 build system is only compatible with bazel higher than 0.10 . Use the latest bazel 0.11.1. See the official documentation to install it.

            • I completely removed with “sudo apt-get remove –purge bazel” and installed by following directions on bazel’s website but still get the same error.

            • Thanks! Can just install this on a virtual env given that I have the drivers installed? Using pip install .whl correct?

  22. Thanks! This was the first comprehensive installation tutorial which worked for this version of Ubuntu. Well done :))

  23. hi, when i command nvidia-smi it says command not found
    the kernel of my ubuntu is 4.13.0-38-generic
    i used to install cuda-9.1 and cudnn 7.0.5 on this version but now it fails.
    what should I do???
    (the version of my ubuntu is 16.04)

    • Have you used the network deb installer ? This is caused by not loading nvidia driver. Go to advanced boot option while booting and select the kernel 4.10 or 4.4 and try again.

      • I installed kernel 4.10 and CUdA 9.1 and cudnn 7.0.5 and tensorflow-gpu (version 1.7)successfully installed, But when I call import tensorflow I see the error below:

        ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

        what I do?
        thank you

        • I think you have installed official wheel which only support cuda 9.0. To suuport cuda 9.1 you have to build it from source as illustrated in the tutorial. Install tf in new virtual environment or upgrade.

  24. Hi, I tried out your tutorial. I got nvidia-smi command not found.
    My linux kernel version is 4.13.0-38-generic

  25. Hello. Thanks for very helpful post. The end result of all the steps on my ubuntu 16.0.4 is
    Successfully installed absl-py-0.1.13 astor-0.6.2 bleach-1.5.0 gast-0.2.0 grpcio-1.10.1 html5lib-0.9999999 markdown-2.6.11 numpy-1.14.2 protobuf-3.5.2.post1 setuptools-39.0.1 six-1.11.0 tensorboard-1.7.0 tensorflow-1.7.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.31.0

    but when i test in python, it says

    >>> import tensorflow as tf
    Traceback (most recent call last):
    File “”, line 1, in
    ModuleNotFoundError: No module named ‘tensorflow’

    Please guide.

    • Seems like tensorflow installed in other python location. Please verify the target of python keyword. May be python3 will work for you. Also check it by using pip list or pip3 list if TF installed then check the associated python and its path by using pip -V or pip3 -V .

      • Thank you very much. Its working now. The mistake i was doing is as i was using conda for environment management but during ./configure i gave python from /usr/bin/python, so although everything was installed nicely but to different location. So when i activated conda environment, the python in it cud not find TF.

        I have one simple question, is TF 1.7 backword compatible with earlier ones like 1.5,1.6 etc. Thanks once again.

  26. Linux kernel version: 4.13.0-37-generic

    I’m getting following error in step 8:
    “bash: nvidia-smi: command not found”

    • Use kernel 4.10 or 4.4 and try again. You can do it from advanced menu on boot screen. If it worked then you can make the changes pemanent by either configuring this option as default or by uninstalling the 4.13.

  27. Thanks Arun! – I was struggling to get Tensorflow with GPU support working after the normal “pip install” operations failed (for reasons including CUDA 9.0 hardcoded (!) and support problems with AMD processors). This post was just what I was looking for – ran through the steps and compiled from source and I have it working!

  28. Thanks Arun! This tutorial saved me time, I was struggling to get my NVidia GTX 1080 to work on Ubuntu. I installed into a fresh Ubuntu 16.04. I then installed with the .whl in Anaconda Python and added Keras, which also worked. However, I have a problem using Spyder.

    I usually launch Spyder remotely using PuTTY and it appears on my Win 10 via XMing server. This works fine except in the environment created using your Tensorflow .whl, which instead gives an error “Could not initialize GLX” in the PuTTY session. Do you have any idea why?

    In fact, in this environment Spyder does not even launch on its own Ubuntu machine. Instead there are a lot of QOpenGLShader errors. I solved this problem by adding

    import ctypes
    ctypes.CDLL(“libGL.so.1”, mode=ctypes.RTLD_GLOBAL)

    into

    site-packages/spyder/app/start.py

    which is a solution I found at this site:

    https://github.com/spyder-ide/spyder/issues/3226

    Do you have any idea what is causing this GLX error? Any help appreciated.

  29. I get the error:
    From Compiling tensorflow/core/kernels/reduction_ops_gpu_double.cu.cc:
    Segmentation fault (core dumped)

    ERROR: /home/usr/tensorflow-1.7.0/tensorflow/core/kernels/BUILD:2820:1: output ‘tensorflow/core/kernels/_objs/reduction_ops_gpu/tensorflow/core/kernels/reduction_ops_gpu_double.cu.pic.o’ was not created
    ERROR: /home/usr/tensorflow-1.7.0/tensorflow/core/kernels/BUILD:2820:1: not all outputs were created or valid
    Target //tensorflow/tools/pip_package:build_pip_package failed to build steps.

    Can someone help me?

  30. Hello,

    I used the GPU build command as well as the CUDA config:
    “`
    bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package

    Do you wish to build TensorFlow with CUDA support? [y/N]: Y
    “`
    However, when I try to see if my GPU is used in tensorflow, i see the following:
    >>> print(device_lib.list_local_devices())
    2018-04-28 17:46:05.352118: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
    [name: “/device:CPU:0”
    device_type: “CPU”
    memory_limit: 268435456
    locality {
    }
    incarnation: 11606757544495911915
    ]

    Can you please help me here? Thank you very much!

    • seems like previous tensorflow is installed. create a new virtual env and install the built wheel there. Are you able to run nvidia-smi ?

      • Hi Arun,

        Thanks for the response.
        Yes, I can run nvidia-smi:
        +—————————————————————————–+
        | NVIDIA-SMI 390.30 Driver Version: 390.30 |
        |——————————-+———————-+———————-+
        | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
        | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
        |===============================+======================+======================|
        | 0 GeForce GTX 1080 Off | 00000000:01:00.0 On | N/A |
        | 0% 49C P8 12W / 215W | 1042MiB / 8116MiB | 12% Default |
        +——————————-+———————-+———————-+

        +—————————————————————————–+
        | Processes: GPU Memory |
        | GPU PID Type Process name Usage |
        |=============================================================================|
        | 0 1305 G /usr/lib/xorg/Xorg 579MiB |
        | 0 2288 G …izichen/pycharm-2018.1.1/jre64/bin/java 17MiB |
        | 0 2881 G compiz 186MiB |
        | 0 9013 G …-token=B651794E15148804B3E0F54CE3A8E6FE 24MiB |
        | 0 21627 G …opt/mendeleydesktop/bin/mendeleydesktop 61MiB |
        | 0 32176 G …-token=2850830C0C1E4A8985F4B065ED057328 149MiB |
        +—————————————————————————–+

        When you say install the built wheel in a new virtual env, do you mean I simply do this command? pip install tensorflow-1.7.0-cp36-cp36m-linux_x86_64.whl

        I did, and the log says requirement already satisfied:
        (udacity) LinuxUser@super-linux:~/tensorflow-1.7.0/tensorflow_pkg$ pip install tensorflow-1.7.0-cp36-cp36m-linux_x86_64.whl
        Requirement already satisfied: tensorflow==1.7.0 from file:///home/LinuxUser/tensorflow-1.7.0/tensorflow_pkg/tensorflow-1.7.0-cp36-cp36m-linux_x86_64.whl in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (1.7.0)
        Requirement already satisfied: tensorboard=1.7.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (1.7.0)
        Requirement already satisfied: six>=1.10.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (1.11.0)
        Requirement already satisfied: termcolor>=1.1.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (1.1.0)
        Requirement already satisfied: absl-py>=0.1.6 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (0.2.0)
        Requirement already satisfied: astor>=0.6.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (0.6.2)
        Requirement already satisfied: wheel>=0.26 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (0.31.0)
        Requirement already satisfied: grpcio>=1.8.6 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (1.11.0)
        Requirement already satisfied: protobuf>=3.4.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (3.5.2.post1)
        Requirement already satisfied: gast>=0.2.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (0.2.0)
        Requirement already satisfied: numpy>=1.13.3 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorflow==1.7.0) (1.14.2)
        Requirement already satisfied: html5lib==0.9999999 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorboard=1.7.0->tensorflow==1.7.0) (0.9999999)
        Requirement already satisfied: bleach==1.5.0 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorboard=1.7.0->tensorflow==1.7.0) (1.5.0)
        Requirement already satisfied: werkzeug>=0.11.10 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorboard=1.7.0->tensorflow==1.7.0) (0.14.1)
        Requirement already satisfied: markdown>=2.6.8 in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from tensorboard=1.7.0->tensorflow==1.7.0) (2.6.11)
        Requirement already satisfied: setuptools in /home/LinuxUser/anaconda3/lib/python3.6/site-packages (from protobuf>=3.4.0->tensorflow==1.7.0) (39.0.1)

        However, when I import tensorflow, there is still no sign of running GPU…

        • use pip install --upgrade --force-reinstall tensorflow-1.7.0-cp36-cp36m-linux_x86_64.whl to install to /home/LinuxUser/anaconda3/lib/python3.6/site-packages or create new conda env using conda create -n tf170gpu python=3.6 and activate using source activate tf170gpu then install tensorflow using pip install tensorflow-1.7.0-cp36-cp36m-linux_x86_64.whl use source deactivate to deactivate environment.

          • Cool! Thank you so much Arun! Creating a new environment resolves the problem! (Although I don’t know why…) Thanks a lot!

  31. Hi all,

    Great article as usual.
    However i get the error : “bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package”

    what should I do ?

    • sorry, i get this as an error from the code above : “The ‘build’ command is only supported from within a workspace.”

      • Hi again, I finally succeed the last step, I had to place the directory in tensorflow.
        But now i got

        “~/tensorflow-1.7.0$ bazel build –config=opt –config=cuda –incompatible_load_argument_is_label=false //tensorflow/tools/pip_package:build_pip_package
        WARNING: /home/mxn/.cache/bazel/_bazel_mxn/7ba1c52055aebe9313fd1fcde736a239/external/protobuf_archive/WORKSPACE:1: Workspace name in /home/mxn/.cache/bazel/_bazel_mxn/7ba1c52055aebe9313fd1fcde736a239/external/protobuf_archive/WORKSPACE (@com_google_protobuf) does not match the name given in the repository’s definition (@protobuf_archive); this will cause a build error in future versions
        ERROR: /home/mxn/tensorflow-1.7.0/util/python/BUILD:5:1: no such package ‘@local_config_python//’: Traceback (most recent call last):
        File “/home/mxn/tensorflow-1.7.0/third_party/py/python_configure.bzl”, line 291
        _create_local_python_repository(repository_ctx)
        File “/home/mxn/tensorflow-1.7.0/third_party/py/python_configure.bzl”, line 253, in _create_local_python_repository
        _check_python_lib(repository_ctx, python_lib)
        File “/home/mxn/tensorflow-1.7.0/third_party/py/python_configure.bzl”, line 196, in _check_python_lib
        _fail((“Invalid python library path: %…))
        File “/home/mxn/tensorflow-1.7.0/third_party/py/python_configure.bzl”, line 27, in _fail
        fail((“%sPython Configuration Error:%…)))
        Python Configuration Error: Invalid python library path: /usr/bin/python3
        and referenced by ‘//util/python:python_headers’
        ERROR: Analysis of target ‘//tensorflow/tools/pip_package:build_pip_package’ failed; build aborted: Loading failed
        INFO: Elapsed time: 3.854s
        FAILED: Build did NOT complete successfully (0 packages loaded)
        currently loading: tensorflow/core … (13 packages)
        Fetching https://mirror.bazel.build/…e-amalgamation-3200000.zip; 27,447b
        Fetching https://mirror.bazel.build/…/archive/4.4.0.tar.gz; 22,629b
        Fetching https://mirror.bazel.build/…4aac68bc8559736e53f.tar.gz; 25,358b
        Fetching https://mirror.bazel.build/…/get/2355b229ea4c.tar.gz; 26,105b

        How can i fix this problem ?

        Thanks ! 🙂

  32. Do this!!! if your bazel build is failing.. thank me later..

    bazel build –config=opt –config=cuda –config=monolithic //tensorflow/tools/pip_package:build_pip_package

3 Trackbacks & Pingbacks

  1. Install GPU version of tensorflow | Python 3.6
  2. Nvidia-powered Tensorflow on a Linux home server in 400,000 easy steps • Cryptocurrency decentral market headlines
  3. ubuntu 16.04 cuda 9.1源代码安装tensorflow-1.7 – LiangXu Wang

Leave a Reply

Your email address will not be published.