Machine Learning, Uncategorized, Windows 10

Running Tensorflow with native Linux Binaries in the Windows Subsystem for Linux

After 4 hours of unsuccessful attempts to set up tensorflow in Docker on Windows, I decided to – just for fun – try to run it in the shiny new Windows Subsystem for Linux on my Windows 10 Insider Preview Build 14332. What began with low expectations turned out to be very successful, so here are the steps:

First enable the Windows Subsystem for Linux in the “Turn Windows features on or off” dialog:

Enabling the Windows Subsystem for Linux
Enabling the Windows Subsystem for Linux

Then open the Ubuntu Bash and update the package index:

Running apt-get update in the Ubuntu Bash
Running apt-get update in the Ubuntu Bash

You can now proceed to install pip for Python 2:

sudo apt-get install python-pip python-dev

Now install the CPU-enabled Linux x64 tensorflow package::

sudo pip install --upgrade

Tensorflow is now installed. With the following command, you can get the directory of the installed package:

python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'

This should give something like “/usr/local/lib/python2.7/dist-packages/tensorflow”.

Now let’s cd to the directory with the example implementation of a CNN for the MNIST dataset:

cd /usr/local/lib/python2.7/dist-packages/tensorflow/models/image/mnist

And run the convolutional neural network:

CNN sample running on the MNIST dataset
CNN sample running on the MNIST dataset

In the end, the run completed with a test set error of 0.8 %.

The final result.
The final result.

That’s it for now – have fun!


  1. matt

    brilliant…I’m glad that worked. I’m struggling with the same thing right now; I’m about to try the Insider Preview build.

  2. Adithya

    Thanks a lot buddy. It just worked perfectly for me.

  3. Brian

    Let me add my thanks as well. This is pretty cool.

  4. sreekar

    Great! I have instead opted for virtual box and ran the MNIST Conv net script and it took a long time. I just want to know how much time yours took to compare with mine and see if I need to switch to docker for better performance

    1. theCake Post author

      Uhless we have the exact same setup there’s no use in comparing runtimes. Especially with MNIST the performance comparison is pretty artificial.

      Do you use CUDA to run on a modern GPU ? Because of you don’t, this should be your primary concern. (My GTX 1060 6GB is about 50x faster than my i7 920…)

      At the moment the Linux subsystem will only give you CPU, so it’s only marginally useful.

      Serious Alternatives:

      I believe tensorflow for Windows has reached public beta.
      For the past few months I’ve been using keras with Theano backend on Windows.

  5. rangu goutham

    It would have been soooomuch for every developer to move forward if WSL supported GPU version of tensorflow..

  6. Allan

    After more than 7 hours trying to set up TensorFlow via “conda” and “bazel”, I gave up. Then using the process you listed – I was a success (in approximately an hour). It worked perfectly and my run took slightly more than 2.5 hours (on a low end laptop), so I would guess it would only take ~5 minutes on a GPU.
    Thank you for posting this so I don’t have to beat on it anymore (just to try TensorFlow on a windows machine).
    I have wanted to do this for months.
    Very nicely done!!
    Thanks again.

Leave a Reply

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