How to set up Tensorflow with GPU CUDA 8 in virtualenv and Python 3.5

Share on Facebook0Share on Google+0Tweet about this on Twitter0Share on LinkedIn0

As the authors say it best

TensorFlow™ is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them.


We use it a lot so in this short post, we want to show you how to setup the TensorFlow environment on your own. The procedure isn’t so complicated but when you want to do it right there are a few gotchas.

If you want to save some time you can always install TensorFlow CPU version on our PLON platform – just launch the console and write:



We are going to use Python 3.5 on ubuntu 16.04 and configure all necessary CUDA library for GPU computing. All the setup will be configured with flexibility in mind so we will use virtualenv. This will let us create separate workspaces for different projects.

If you are impatient all procedure was described in this Github Gist The documentation presents many different ways how to install TF, we just want to show one simple and quick procedure.


Install Nvidia drivers

At the beginning we have to install or upgrade our graphic card drivers, we do this by adding new ubuntu repository ppa:graphics-drivers/ppa and use apt-get to install a new driver.

After installation, it is worth to check nvidia-smi in order to see if your driver is properly installed. This should look like this:


Nvidia smi output

Install CUDA and cuDNN libraries

The second step is to install all necessary CUDA libraries. Please download CUDA Toolkit for your platform and cuDNN library. The latter requires registering to Accelerated Computing Developer Program and answering a few question. In the time of writing the recommended are CUDA 8 and cuDNN 5.1.

The important thing is installing CUDA in /usr/local/cuda folder, you will have fewer problems in the future with paths. For me, the best way for installing Cuda Toolkit is through “runfile (local)” (the script size is almost 1.4GB).  When you execute the script you have to be careful and read all questions, the most important is this “Install NVIDIA Accelerated Graphics Driver?” you should answer “‘no”. We had already installed the newer version.

After successful installation, we have to copy all cuDNN library files to CUDA folder

Install Tensorflow in virtulalenv

The final part is to install python, virtualenv and library itself. We download python3 package and python3-venv. The next step is creating a new virtualenv workspace called tfenv. We activate it and install tensorflow-gpu pip package.

To verify the installation you can type few simple command in python interactive console:


“TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.”

Share on Facebook0Share on Google+0Tweet about this on Twitter0Share on LinkedIn0

Leave a Reply

Your email address will not be published. Required fields are marked *