How to install TensorFlow on Windows without Docker / Virtual Machines

There are all sorts of ways to get TensorFlow running on a Windows PC. The way that I've been doing it up until last month was to install and set up Docker (which involves installing and setting up Oracle VM VirtualBox) and then run TensorFlow in the Docker container in a virtual machine. Besides being very complicated, there's no good way for TensorFlow to access a GPU through a Docker container through a virtual machine.

This all changed with the release of TensorFlow 0.12 in late November 2016 which added support for Windows.

So here's how I installed TensorFlow on Windows without Docker or virtual machines.

The installation notes

It's a little buried in the installation notes, but here's the important part:

TensorFlow supports only 64-bit Python 3.5 on Windows.

So I first went to python.org and clicked the big 'Download Python 3.5.2' button. The installer popped up this screen:

This is the wrong version!

So I cancelled out of that, and went to the downloads page, and selected the 3.5.2 download:

This then takes you to another page and you must select the x86-64 or amd64 installer. To be specific, I picked the Windows x86-64 executable installer.

I chose to add Python 3.5 to PATH and it installed. The last message I saw was 'Setup was successful'.

To confirm, I opened up a command prompt and checked the version.

Okay, on to installing TensorFlow with pip. From the installation instructions:

Note that I chose to install the CPU-only version of TensorFlow, but there's an option to install the GPU version of TensorFlow as well by choosing a different .whl file here. If you want to install the GPU version, be sure to read my note at the end of this article.

pip install --upgrade  https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc1-cp35-cp35m-win_amd64.whl
Collecting tensorflow==0.12.0rc1 from https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc1-cp35-cp35m-win_amd64.whl
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',))': /tensorflow/windows/cpu/tensorflow-0.12.0rc1-cp35-cp35m-win_amd64.whl
Operation cancelled by user

Uh oh! This is likely due to my corporate firewall. You may not run into this problem. This is remedied by supplying a proxy:

SET HTTPS_PROXY=<proxyHost>:<proxyPort>

This got me a little closer...

The last error reads:

PermissionError: [WinError 5] Access is denied: 'c:\\program files\\python35\\Lib\\site-packages\\numpy'

It also gave me a warning that my pip installation was a little old, but I don't think that's an issue. I need to run the cmd prompt as an administrator.

Here's how you do that. Open up the start menu, search for cmd and then right click on it and run as an administrator.

This might be because I installed Python 3 for all users (instead of just me), and it's trying to install numpy to the same spot as that installation... or at least that's my guess. Again, you might not run into this problem.

Anyways, this worked. You'll notice in the top left corner the command prompt says 'Administrator' and the installation completed successfully.

Testing my TensorFlow installation

The official installation instructions suggest testing out your TensorFlow installation, so I opened up a command prompt and wrote the following:

It's a good way to make sure everything is working correctly.

Troubleshooting errors

On another computer running Windows 7, after using pip to install TensorFlow, I ran into this error

ImportError: DLL load failed: The specified module could not be found.
ImportError: No module named '_pywrap_tensorflow'

As the installation instructions note, I need to install the the Visual C++ 2015 redistributable (x64 version) which fortunately is not a large file

I did need to restart my computer though. Then I tested out my installation and everything worked great.

GPU enabled TensorFlow

On a different computer I got a special error after installing the GPU enabled version and testing out my installation

The errors read as

>>> import tensorflow as tf
... Couldn't open CUDA library cublas64_80.dll
... Unable to load cuBLAS DSO.
... Couldn't open CUDA library cudann64_6.dll
... Unable to load cuDNN DSO.
... Couldn't open CUDA library cufft64_80.dll
... Unable to load cuFFT DSO.
... successfully opened CUDA library nvcuda.dll locally
... Couldn't open CUDA library curand64_80.dll
... Unable to load cuRAND DSO.
>>>

which is because I need to install the CUDA Toolkit 8.0 and cuDNN v5.1

This turned out to be lengthy and involved enough that I wrote a separate article on installing and running GPU enabled TensorFlow on Windows so be sure to read that if you want to use your GPU.

Otherwise, the CPU installation steps above should work fine.