How to Install Tensorflow-GPU version with Jupyter (Windows 10) in 8 easy steps.
Why should I install GPU version ?
If you have a GPU, why not use it.
More Formally, in the words of Google, “TensorFlow programs typically run significantly faster on a GPU than on a CPU. Therefore, if your system has a NVIDIA® GPU and you need to run performance-critical applications, you should ultimately install the GPU version”.
1 ) Check if your GPU is supported
Steps:
i) Go to command prompt-> windows+r->cmd->enter
ii) Paste the command & enter: wmic path win32_VideoController get name
iii) Go to this link to find out supported GPU.
If the name of your GPU is present, then you can install GPU supported tensorflow.
We will be needing to use Anaconda to awaken “Jupyter Notebook” and the dependencies of tensorflow.
Steps:
i) Download and install the latest Anaconda installer from here
You need to install Cuda Toolkit 8.0 and cuDNN v5.1 as the GPU version works best with these.
Download and install CUDA Toolkit
Toolkit version 8.0 or above: https://developer.nvidia.com/cuda-downloads
Example installation directory: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
Download and install cuDNN
You would need to signup at Nvidia in order to download these files.
After signing up, login to your account.
Now extract the cuDNN files into your Toolkit directory.
Very Important: Check for the Environment variables
Steps:
i) Hit windows+s -> Search for “Environment Variables”
Check if your CUDA_HOME, CUDA_PATH & CUDA_PATH_V8 is set up properly. If not add it.
ii) Check if your PATH variable has all of the highlighted components. If not, add them.
Create conda environment
Create new environment, with the name tensorflow-gpu and python version 3.5.2
Steps:
i) Go to Anaconda command prompt (search for Anaconda in windows+s)
ii)Paste the command : conda create -n tensorflow-gpu python=3.5.2
Hit “Y” when asked
Activate the environment activate tensorflow-gpu
Install tensorFlow
pip install tensorflow-gpu
Now, tensorflow GPU is successfully installed in your machine.
Before proceeding further, let us check if our installation is correct, and the GPU is correctly mapped.
6) Check your tensorflow-gpu installation
i) Activate environment we created
activate tensorflow-gpu
ii) Test GPU
Enter into python shell
python
import tensorflow as tf
Now run this command and check if it identifies your GPU.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
Even if you already have Jupyter, you need to do this to map tensorflow into it.
i) Install Jupyter Notebook
pip install jupyter Notebook
ii) Install Pandas. It will help you in development
iii) Start your Notebook
Go to the link given to access your notebook.
Enter the following commands in notebook cell:
import tensorflow as tf
Hurray ! you have successfully installed GPU supported tensorflow and executed tensorflow command in your Jupyter Notebook
Install TensorFlow on Windows and a Virtual Environment¶
TensorFlow is now supported in Windows, yay! The very simple installation instructions for Windows are here. All you need to do to get the non-GPU (normal person with normal laptop) version is create an new virtual environment and install tensorflow:
Note that the above install command didn’t work for me, as documented in this ticket here and here. The solution was to download a nightly build and just directly install the binary wheels file with pip:
You’ll still get warnings, but they are OK. Now, you want to be able to use jupyter notebooks inside your tensorflow environment, so refer to this great stack overflow explanation of how to make Jupyter recognize conda environments as kernels. Essentially you just need your environment to have three packages:
Then make sure to restart the jupyter server and select kernel > change kernel to change this notebooks environment! Now we are ready to test our tensorflow install!
In the above image squares represent stateful objects whereas circles represent computes.
Visualizing Graphs Inline in Jupyter¶
Thanks to this stackoverflow answer which pointed me to this awesome notebook in which some functions are defined for inline visualization (relying on the built-in TensorBoard visualization capabilities). Copy/pasting from there (but commenting out so that my «notebook to HTML plugin» for generating articles doesn’t act funny):
Also check out this good article on how to use name s and namespaces in your graph to get sensible and legible visualizations from TensorBoard. It follows the official docs on the same topic.
Finally, another helpful thing to know before starting is the function to clear the default graph of all its nodes so you can start fresh:
Computational Graphs¶
The key to not being intimidated by tensor flow is having a basic grasp of what computational graphs are before you jump in. There are only two resources you need here, and I recommend you avail yourself of both:
-
on computational graphs and backprop. introducing computational graphs. You only need to watch the first 50 minutes.
Walkthrough of TensorFlow Official «Get Started» Guide¶
This is a walk-through of the official «Get Started» tutorial under the «Develop» tab at tensorflow.org here. In my walkthrough I will show the evolution of the computational graph in a lot more detail and I try to explain the steps in terms of editing the graph.
Overview¶
TensorFlow exposes various levels of API, the high-level one is tf.contrib.learn , but many people instead use the external python library keras to provide a simpler high-level syntax for working with TF. The lowest level API is called TensorFlow Core (TFC) and provides the maxmium amount of flexibility. TFC scripts consist of building a computational graph and then running that graph. According to the documentation:
A computational graph is a series of TensorFlow operations arranged into a graph of nodes. Each node takes zero or more tensors as inputs and produces a tensor as an output.
This is the source of the name «TensorFlow» — the basic function of this tool is to flow tensors around in a graph! Remember, tensors can be scalar constants, vectors, matrices and higher-dimensional arrays.
Constants¶
One type of node is tf.constant which takes zero inputs and outputs a stored 0D tensor. The value of a constant node is not it’s stored value, instead when that node is evaluted during the running a graph it outputs its stored value. A graph can also include operation nodes like tf.add .
You use your python or C++ front-end (THIS) to build your graph, but then the graph is sent to your runtime for actual computation. You talk to the run-time via a Session , which is the object responsible for controlling and holding state for the TF runtime.
We can build a simple graph with a few constants and a few operations and then run it to force those nodes to be evaluated. Notice we can give names to our nodes and make the graph easier to understand:
Running Tensorflow in Jupyter Notebook
I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called tensorflow as follows
Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment
You can see that jupyter is also installed.
Now, when I open up the Python interpreter in this environment and I run the basic TensorFlow command, it all works fine. However, I wanted to do the same thing in the Jupyter notebook. So, I created a new directory (outside of this environment).
In that, I activated tensorflow environment
And I can see the same list of packages in that.
Now, I open up a Jupyter notebook
It opens up a new notebook in the browser. But when I just import basic python libraries in that, like pandas, it says «no packages available». I am not sure why is that when the same environment has all those packages and in the same directory, if I use Python interpreter it shows all packages.
How to Download & Install Tensorflow in Jupyter Notebook
In this tutorial, we will explain how to install TensorFlow Anaconda Windows. You will learn how to use TensorFlow in Jupyter Notebook. Jupyter is a notebook viewer.
TensorFlow Versions
TensorFlow supports computations across multiple CPUs and GPUs. It means that the computations can be distributed across devices to improve the speed of the training. With parallelization, you don’t need to wait for weeks to obtain the results of training algorithms.
For Windows user, TensorFlow provides two versions:
- TensorFlow with CPU support only: If your Machine does not run on NVIDIA GPU, you can only install this version
- TensorFlow with GPU support: For faster computation, you can download TensorFlow GPU supported version. This version makes sense only if you need strong computational capacity.
During this tutorial, the basic version of TensorFlow is sufficient.
Note: TensorFlow does not provides GPU support on MacOS.
Here is how to proceed
- Install Anaconda
- Create a .yml file to install Tensorflow and dependencies
- Launch Jupyter Notebook
- Install Anaconda
- Create a .yml file to install dependencies
- Use pip to add TensorFlow
- Launch Jupyter Notebook
To run Tensorflow with Jupyter, you need to create an environment within Anaconda. It means you will install Ipython, Jupyter, and TensorFlow in an appropriate folder inside our machine. On top of this, you will add one essential library for data science: “Pandas”. The Pandas library helps to manipulate a data frame.
Install Anaconda
Download Anaconda version 4.3.1 (for Python 3.6) for the appropriate system.
Anaconda will help you to manage all the libraries required either for Python or R. Refer this tutorial to install Anaconda
Create .yml file to install Tensorflow and dependencies
- Locate the path of Anaconda
- Set the working directory to Anaconda
- Create the yml file (For MacOS user, TensorFlow is installed here)
- Edit the yml file
- Compile the yml file
- Activate Anaconda
- Install TensorFlow (Windows user only)
Step 1) Locate Anaconda,
The first step you need to do is to locate the path of Anaconda.
You will create a new conda environment that includes the necessaries libraries you will use during the tutorials about TensorFlow.
Windows
If you are a Windows user, you can use Anaconda Prompt and type:

We are interested to know the name of the folder where Anaconda is installed because we want to create our new environment inside this path. For instance, in the picture above, Anaconda is installed in the Admin folder. For you, it can the same, i.e. Admin or the user’s name.
In the next, we will set the working directory from c:\ to Anaconda3.
MacOS
for MacOS user, you can use the Terminal and type:

You will need to create a new folder inside Anaconda which will contains Ipython, Jupyter and TensorFlow. A quick way to install libraries and software is to write a yml file.
Step 2) Set working directory
You need to specify the working directory where you want to create the yml file.
As said before, it will be located inside Anaconda.
For MacOS user:
The Terminal sets the default working directory to Users/USERNAME. As you can see in the figure below, the path of anaconda3 and the working directory are identical. In MacOS, the latest folder is shown before the $. The Terminal will install all the libraries in this working directory.
If the path on the text editor does not match the working directory, you can change it by writing cd PATH in the Terminal. PATH is the path you pasted in the text editor. Don’t forget to wrap the PATH with ‘PATH’. This action will change the working directory to PATH.

Open your Terminal, and type:
For Windows user (make sure of the folder before Anaconda3):
or the path “where anaconda” command gives you

Step 3) Create the yml file
You can create the yml file inside the new working directory.
The file will install the dependencies you need to run TensorFlow. Copy and paste this code into the Terminal.
For MacOS user:
A new file named hello-tf.yml should appear inside anaconda3

For Windows user:
A new file named hello-tf.yml should appear

Step 4) Edit the yml file
You are ready to edit the yml file.
For MacOS user:
You can paste the following code in the Terminal to edit the file. MacOS user can use vim to edit the yml file.
So far, your Terminal looks like this

You enter an edit mode. Inside this mode, you can, after pressing esc:
- Press i to edit
- Press w to save
- Press q! to quit
Write the following code in the edit mode and press esc followed by :w

Note: The file is case and intend sensitive. 2 spaces are required after each intend.
Code Explanation
- name: hello-tf: Name of the yml file
- dependencies:
- python=3.6
- jupyter
- ipython
- pandas: Install Python version 3.6, Jupyter, Ipython,and pandas libraries
- pip: Install a Python library
- https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl: Install TensorFlow from Google apis.
Press esc followed by :q! to quite the edit mode.

For Windows User:
Windows does not have vim program, so the Notepad is enough to complete this step.
Enter following into the file
- name: hello-tf: Name of the yml file
- dependencies:
- python=3.6
- jupyter
- ipython
- pandas: Install Python version 3.6, Jupyter, Ipython,and pandas libraries
It will open the notepad, you can edit the file from here.

Note: Windows users will install TensorFlow in the next step. In this step, you only prepare the conda environment
Step 5) Compile the yml file
You can compile the .yml file with the following code :
Note: For Windows users, the new environment is created inside the current user directory.
It takes times. It will take around 1.1gb of space in your hard disk.


Step 6) Activate conda environment
We are almost done. You have now 2 conda environments.
You created an isolated conda environment with the libraries you will use during the tutorials. This is a recommended practice because each machine learning project requires different libraries. When the project is over, you can remove or not this environment.

The asterix indicates the default one. You need to switch to hello-tf to activate the environment
For Windows user:

You can check all dependencies are in the same environment. This is important because it allows Python to use Jupyter and TensorFlow from the same environment. If you don’t see the three of them located in the same folder, you need to start all over again.

Optional: You can check for update.
Step 7) Install TensorFlow For Windows user
For windows user:

As you can see, you now have two Python environments. The main one and the newly created on i.e. hello-tf. The main conda environment does not have tensorFlow installed only hello-tf. From the picture, python, jupyter and ipython are installed in the same environment. It means, you can use TensorFlow with a Jupyter Notebook.
You need to install TensorFlow using pip command. Only for Windows user

How to Import Tensorflow in Jupyter Notebook
This part is the same for both OS. Now, let’s learn how to import TensorFlow in Jupyter Notebook.
You can open TensorFlow with Jupyter.
Note: Each time you want to open TensorFlow, you need to initialize the environment
You will proceed as follow:
- Activate hello-tf conda environment
- Open Jupyter
- Import tensorflow
- Delete Notebook
- Close Jupyter
Step 1) Activate conda
For Windows user:

Step 2) Open Jupyter
After that, you can open Jupyter from the Terminal

Your browser should open automatically, otherwise copy and paste the url provided by the Terminal. It starts by http://localhost:8888
Inside the TensorFlow Jupyter Notebook, you can see all the files inside the working directory. To create a new Notebook, you simply click on new and Python 3
Note: The new notebook is automatically saved inside the working directory.

Step 3) Import Tensorflow
Inside the notebook, you can import TensorFlow in Jupyter Notebook with the tf alias. Click to run. A new cell is created below.

Let’s write your first code with TensorFlow.
A new tensor is created. Congratulation. You successfully install TensorFlow with Jupyter on your Machine.

Step 4) Delete file
You can delete the file named Untitled.ipynb inside Jupyer.

Step 5) Close Jupyter
There are two ways of closing Jupyter. The first way is directly from the notebook. The second way is by using the terminal (or Anaconda Prompt)
From Jupyter
In the main panel of Jupyter Notebook, simply click on Logout

You are redirected to the log out page.

From the terminal
Select the terminal or Anaconda prompt and run twice ctr+c.
The first time you do ctr+c, you are asked to confirm you want to shut down the notebook. Repeat ctr+c to confirm


You have successfully logged out.
Jupyter with the main conda environment
If you want to launch TensorFlow with jupyter for future use, you need to open a new session with