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.

Step 8: Go to terminal and type:

nano ~/.bashrc

In the end of the file, add:

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

ctrl+x then y to save and exit

source ~/.bashrc
sudo ldconfig
nvidia-smi

Check driver version.

(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 this link and download the required files. (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
source ~/.bashrc
sudo ldconfig

Step11: Download whl file

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

For eg., if your python version is 3.5 and os is linux then select

tensorflow_gpu-1.7.0-cp35-cp35m-manylinux1_x86_64.whl

Step 12: Install whl file

Create a new virtual environment and activate it then install the whl file using the command.

for python 2:

pip2 install [whl file path]

for python 3:

pip3 install [whl file path]

Step 13: Verify Tensorflow installation

Verify tensorflow using following commands:

$ python

>>> 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()

Note:- It may take some time after tf.Session() for first time.

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

For Windows-64bit OS:

Install CPU Version of Tensorflow:

I have already mentioned the condition in which CPU version of tensorflow is preferable to the GPU version earlier in the post. Let’s get right to how to install tensorflow CPU version for windows OS.

Step1: Download whl file

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

For eg., if your python version is 3.5 and os is Windows then select

tensorflow-1.7.0-cp35-cp35m-win_amd64.whl

Step 2: Install whl file

Create a new virtual environment and activate it then install the whl file using the command.

for python 2:

pip2 install [whl file path]

for python 3:

pip3 install [whl file path]

Step 3: Verify tensorflow installation

Verify tensorflow is properly installed using the following commands:

$ python

>>> 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 Windows OS.

Install GPU Version of Tensorflow:

GPU tensorflow is recommended for intermediate to advanced users. For users who work with large dataset, the GPU version is almost a necessity as it can greatly speed up training time. 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 Windows.

Step 1: Verify you have a CUDA-Capable GPU:

Before doing anything else, you need to verify that you have a CUDA-Capable GPU in order to install tensorflow GPU. You can verify that you have a CUDA-capable GPU through the Display Adapters section in the Windows Device Manager. Here you will find the vendor name and model of your graphics card(s).

The Windows Device Manager can be opened via the following steps:

Open a run window from the Start Menu or (Win+R)

Run:

control /name Microsoft.DeviceManager

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 2: Download the NVIDIA CUDA Toolkit:

Go to this link and download Installer for Windows > x86_64 > 10 > exe[network]

Uninstall Nvidia and Cuda related programs from Control Panel > Program and Features.

If a reboot is required, then reboot.

Install it in default location with default settings. It will update your GPU driver if required.

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

Step 4: Install cuDNN 7.1.2:

Goto this link and download the necessary files. (Membership required)

After login, download the following:

cuDNN v7.1.2 Library for Windows [your version]. For me, it’s Windows 10

Goto downloaded folder and extract cudnn-9.0-windows[your version]-x64-v7.zip

Go inside extracted folder and copy all files and folder from cuda folder (eg. Bin, include, lib) and paste to “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0”.

Step 5: Download whl file

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

For eg., if your python version is 3.5 and os is Windows then select

tensorflow_gpu-1.7.0-cp35-cp35m-win_amd64.whl

Step 6: Install whl file

Create a new virtual environment and activate it then install the whl file using the command.

for python 2:

pip2 install [whl file path]

for python 3:

pip3 install [whl file path]

Step 7: Verify tensorflow installation

Verify tensorflow using following commands:

$ python

>>> 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()

Note:- It may take some time after tf.Session() for first time.

This is all you need to do to install tensorflow GPU version on Windows OS.

If you follow the steps mentioned above carefully, you will be able to install tensorflow both CPU and GPU version on Ubuntu as well as Windows OS. If you encounter any problem during the process, do let us know in the comments and we will help you.

 

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

  1. 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!

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

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

  4. 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!

  5. 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!

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

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

  7. Greatly detailed tutorial running windows 10 and linux ubuntu 17.10 under cpu.
    Ran a LTSM ANN Tutorial from tensorflows website took hours trying gpu under linux python 3.6 so had to change version number
    sudo apt-get install python2.7-dev python3.5-dev pylint
    to
    sudo apt-get install python2.7-dev python3.6-dev pylint

  8. I am running ubuntu linux 17.10 and gcc 7 seems to be a issue but maby something else is wrong it is not responding.
    Python 3.6.3 (default, Oct 3 2017, 21:45:48)
    [GCC 7.2.0] on linux
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import tensorflow as tf
    >>> hello = tf.constant(‘Hello, TensorFlow!’)
    >>> sess = tf.Session()
    2018-03-08 13:00:07.668057: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
    2018-03-08 13:00:07.817236: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    2018-03-08 13:00:07.817807: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
    name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 1.176
    pciBusID: 0000:04:00.0
    totalMemory: 1.96GiB freeMemory: 1.61GiB
    2018-03-08 13:00:07.817849: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
    sess.run(hello)

  9. I am trying to install sonnet to try the Differentiable neural computer example so far no luck.
    I tried installing it from source because I could not get the packages to work.
    File “/home/joshua/sonnet/sonnet/python/modules/base_info.py”, line 24, in
    from sonnet.protos import module_pb2
    ImportError: cannot import name ‘module_pb2’

  10. I had a successful tensorflow with GPU installation from tensorflow_gpu-1.7.0rc1-cp36-cp36m-win_amd64.whl untill tried to update by running tensorflow_gpu-1.7.0-cp36-cp36m-win_amd64.whl

    Everything looked fine untill
    Found existing installation: tensorboard 1.6.0
    Uninstalling tensorboard-1.6.0:
    Successfully uninstalled tensorboard-1.6.0
    Found existing installation: tensorflow-gpu 1.7.0rc1
    Uninstalling tensorflow-gpu-1.7.0rc1:
    Exception:
    Traceback (most recent call last):
    File “c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\shutil.py”, line 544, in move
    os.rename(src, real_dst)
    FileNotFoundError: [WinError 3] The system cannot find the path specified: ‘c:\\program files (x86)\\microsoft visual studio\\shared\\python36_64\\lib\\site-packages\\tensorflow\\contrib\\tensor_forest\\hybrid\\python\\models\\__pycache__\\stochastic_hard_decisions_to_data_then_nn.cpython-36.pyc’ ->

    After this tensorflow fails. Please help the cleanup… I don’t have the relevant restore point.

    • Rename python36_64 with other name and download 64 bit python zip and extract it to same name then install tensorflow in fresh python package.

  11. I am simply trying to install the CPU version on Windows 7. The installation has gone fine but on trying import tensorflow I get:

    File “C:\Program Files\Python36\lib\importlib\__init__.py”, line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    ImportError: DLL load failed: The specified procedure could not be found.

    From what I read I think this is something to do with the PATH but have reached an impass

  12. Great. This was really helpful. Not really used to windows but these steps saw me through. Of course I have to do back and forth with versions but still, this made life pretty easy. thanks a ton.

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.