How to install Tensorflow 1.7.0 using official pip package

Easiest method to install official pre-built tensorflow pip packages for both CPU and GPU versions on Ubuntu and Windows.

Hello everyone. This is going to be a tutorial on how to install tensorflow using official pre-built pip packages. To install tensorflow with pip packages is easier as compared to building using CMake or Bazel. Pre-built pip package are fully tested officially. However, since they are configured in such a way that they can support legacy hardware too, using pip package may not use full capability on your new and powerful hardware. Building pip package the solution to fully optimize tensorflow to use full capability of your hardware. However, building is a time-consuming process and generally recommended for advanced users only. If you are looking to build tensorflow instead, you can check out our other blog posts:

  1. For Ubuntu 16.04
  2. For Windows 10

In this tutorial, we will look at how to install tensorflow CPU and GPU both for Ubuntu as well as Windows OS. For our purpose, we will look at installing the latest version tensorflow, tensorflow 1.7.0, at the time this blog is published. To install tensorflow in any OS, I highly recommended using virtual environment setup (conda, virtualenv etc.). Currently only 64-bit python is supported by Tensorflow.

We have also performed speed comparison on the tensorflow 1.5.0 with CUDA 9 and cuDNN 7.5 support with tensorflow 1.4.1 with CUDA 8 and cuDNN 6 to calculate just how faster the new version of tensorflow is in comparison. You can click on the link here to check that out.

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

For Ubuntu 16.04 64bit OS:

Install CPU Version of Tensorflow:

CPU version of tensorflow is recommended for new users of tensorflow. Unless you are handling large datasets, CPU version of tensorflow works just fine. Also, this is the simplest method to install tensorflow.

Step1: Download whl file

Goto https://pypi.python.org/pypi/tensorflow and download whl pacakage related to your python version and os.

For eg. If your tensorflow version is 1.7.0, your python version is 3.5, and OS is linux then select tensorflow-1.7.0-cp35-cp35m-manylinux1_x86_64.whl

Step 2: Install whl file

Create a new virtual environment and activate it then install the whl file using the command. If you are having trouble setting up a virtual environment, you can refer to our other article here.

for python 2:

pip2 install [whl file path]

for python 3:

pip3 install [whl file path]

Step 3: Verify tensorflow installation

Verify tensorflow using following commands:

$ python3

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a + b)
42
>>> sess.close()

This is all you need to do to install tensorflow CPU version on Ubuntu 16.04.

Install GPU Version of Tensorflow:

Using GPU version of tensorflow will greatly speed up training dataset time. Once you are working with large datasets, it is impractical to rely only on CPU for deep learning. Tensorflow GPU is recommended for intermediate to advanced users and anyone who works with handling large dataset. Advanced users who want to build pip package to get optimum performance can follow the link at the top of the article to build tensorflow gpu for ubuntu.

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 go to http://developer.nvidia.com/cuda-gpus and verify if listed in CUDA enabled GPU list.

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.0

Step 4: Install Dependencies:

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 type the following command:

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

Step 6: Download the NVIDIA CUDA Toolkit:

Go to this link and download Installer for Linux > x86_64 > Ubuntu > 16.04 > 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.0.176-1_amd64.deb

If you have Cuda 9.1 or other version installed then this tensorflow prebuilt package will not work. Remove nvidia cuda related files (drivers, Cuda Toolkit, etc)

sudo apt-get purge nvidia*
sudo apt-get auto-remove

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.0.176-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda-9.0

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

27 Comments on How to install Tensorflow 1.7.0 using official pip package

  1. I’m not a very experienced programmer or IT expert. I have installed Python 3.6 and I now try to install Tensorflow. When I try to install Tensorflow I get numerous error messages ‘Invalid Syntax’. I enter ‘pip3 install + the path to the tensorflow file’ . Please help!

    • There may be error due to wrong whl file. Use appropriate whl file according to your platform and python version and ensure that python is 64 bit. Also you can use pip3 install --upgrade tensorflow for cpu version and pip3 install --upgrade tensorflow-gpu for gpu version.

    • You can use the whl with 36 and win. Simply use pip install tensorflow for cpu or pip install tensorflow-gpu also works.

  2. Thanks for the marvelous posting! I seriously enjoyed reading it, you may be a great author.
    I will make certain to bookmark your blog and will come back in the future.
    I want to encourage you to continue your great job, have a nice weekend!

  3. Hi,
    First, thanks a lot for this tutorial, it helps a lot!
    However I still got an error when checking the installation (Ubuntu 16.04 64bit) :

    2018-02-10 14:52:51.176978: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1168] Ignoring visible gpu device (device: 0, name: GeForce GTX 760, pci bus id: 0000:01:00.0, compute capability: 3.0) with Cuda compute capability 3.0. The minimum required Cuda capability is 3.5.

    And also something weird, the code ‘sess.run(hello)’ returns :
    b’Hello, TensorFlow!’ (not sure where this ‘b’ comes from!)

    If anyone already had the same pb and/or has an idea I’d be happy to hear your thoughts. Thanks!

  4. Hi.

    I follow the step until 7, when I run “import tensorflow as tf” in python, i met:

    ImportError: Could not find ‘cudart64_90.dll’. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL: https://developer.nvidia.com/cuda-toolkit

    I’m sure I installed cuda according the step 2/3/4.
    Are there anything that I missed?

    some info:
    System: Windows 10
    GPU: GTX 965M
    cuda install exe: cuda_9.0.176.1_windows.exe
    cudnn: cudnn-9.0-windows10-x64-v7
    Python version: Python 3.6.4 :: Anaconda, Inc.
    tensorflow wheel: tensorflow_gpu-1.6.0rc0-cp36-cp36m-win_amd64.whl
    NVDIA program in “Programs and Features”:
    1. NVDIA CUDA Development 9.0
    2. NVDIA CUDA Runtime 9.0
    3. NVDIA Image Drive Program 388.08
    4. NVDIA update 29.1.0.0

    Thank You!

      • Same problem…
        I use “tensorflow_gpu-1.5.0-cp36-cp36m-win_amd64.whl”, when I run “import tensorflow as tf”, I met:

        ImportError: Could not find ‘cudart64_90.dll’. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL: https://developer.nvidia.com/cuda-toolkit

    • More info:
      I try to find “cudart64_90.dll” but can’t.
      In the location “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin”, I only got three file: cublas64_90.dll, cudnn64_7.dll, nvblas64_90.dll.

      I try to find similar program in Google. It’s seem that i installed cudnn9.0 failed? but I can find CUDA program in “Program and Features” as last comment….

      • I think re-installation of Cuda 9.0 should work. Uninstall All Nvidia and Cuda related programs from Control Panel > Program and Features. Try again ! And verify the files and its location in system environment.

        • The problem is that I have tried re-installation of Cuda 9.0 and I uninstall All these problem that hava “NVDIA” in its name before re-installation and I reboot after every step.=_=

          Can you tell me if there is “cudart64_90.dll” file in your cudnn/bin or any dic in PATH?

      • More info 2:
        I try to check my PATH variable:
        only find:
        1. “%SystemRoot%\system32”
        2. “%SystemRoot%”
        3. “%SystemRoot%\System32\Wbem”
        4. “%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\”
        5. “%SYSTEMROOT%\System32\LibreSSL\”
        6. “%SYSTEMROOT%\System32\OpenSSH\”

        I can’t find any dll about cudnn or cudart64_90.dll in these dic.

        • cudart64_90.dll exists in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin for me.

          • got it.

            It’s because I use wrong installer for cuda= =

            “cuda_9.0.176.1_windows.exe” isn’t right installer.
            I downloaded “cuda_9.0.176_win10_network.exe” and it works good.

            Now everything is Ok.

            Thank you~~ O.O

            • Thanks for information. That’s why i always recommended network installation.

  5. Thanks for this! It worked! I installed tensorflow-gpu but it didn’t connect to my two gpu cards, after a day of struggling I am happy I found this installation guide. It only worked for me when I installed using pip3!

    • I am glad to hear that it worked for you. It is good to use virtual environment then directly installing to main python installation.

  6. I follow the steps until 5.

    I am using python3.6 on Windows10 cause people said TF1.5 support it, and I also see the download link for it.

    but when I run pip install tensorflow_gpu-1.5.0-cp36-cp36m-win_amd64.whl

    Error –>”tensorflow_gpu-1.5.0-cp36-cp36m-manylinux1_x86_64.whl is not a supported wheel on this platform.”

    Are there anything that I missed?

    • You have downloaded linux version. Use windows version. ‘pip install tensorflow-gpu’ simply works. Also make sure pip belongs to python 3.6 by command ‘pip –version’. May be pip3 install [whl] should work. Use virtualenv if possible.

      • I download default python3.6 version which is 32bit. after correct the python version, everything works fine. Thank you at the same!

1 Trackbacks & Pingbacks

  1. 1 – Tensorflow 1.5.0 CPU and GPU installation for linux and windows

Leave a Reply

Your email address will not be published.




This site uses Akismet to reduce spam. Learn how your comment data is processed.