Running TensorFlow in Bash on Windows

TensorFlow is a library of machine learning code. TensorFlow is intended for use on Linux machines. In principle, it’s possible to compile TensorFlow source code on a Windows machine, but the details are very tricky. So, instead, I decided to see if TensorFlow would work inside a Linux Bash shell running on Window 10. It does.

I think of Bash on Windows as a miniature Linux (Ubuntu to be exact) environment that runs on a Windows machine. Installing Bash on Windows isn’t difficult and there are plenty of reference on the Internet, but briefly: Control Panel | Programs | Windows Features | “Windows Subsystem for Linux (Beta)” | OK. After a reboot, Run | Bash -> Do you want to install? -> Y. Then after the install completes, you must create a Linux User (I used “jamccaff”) and a password for the user.

Under the covers, TensorFlow is written in C++ but you use the Python programming language to interact with Tensorflow, so I needed Python in my Bash shell. Luckily, Bash on Windows comes with Python 2.7 built-in. But to install TensorFlow I needed the PIP (“Pip installs packages”) tool so from the Bash ‘$’ prompt:

$ sudo apt-get install python-pip python-dev
$ pip --version

Next I used pip to install TensorFlow:

$ sudo pip install --upgrade

Somewhat miraculously, the package built and installed without too many problems. The main issues I ran into were related to an incompatible version of TensorFlow with my Linux version. Next, I tested the TensorFlow installation:

$ python
>>> import tensorflow as tf
>>> m = tf.constant("This is a TF message")
>>> s = tf.Session()
>>> print(
This is a TF message


And that worked too. I got ambitious and searched the Internet for a simple logistic regression example and found one that used the MNIST digit image data set, copied that script into the Notepad++ editor, saved it as in a Windows directory and successfully ran it too (Bash on Windows can access files in the Windows file system as well as files in the Linux file system. Cool!) There were a few glitches because TensorFlow is still under development and many of the code examples I’ve found required small changes. But I was expecting much more trouble. Bottom line: If you want to run TensorFlow on Windows, use can definitely use Bash for Windows instead of trying to build TensorFlow directly.

Note: I believe TensorFlow in Bash on Windows runs in CPU mode only, not in GPU mode. This could be an important limitation for some scenarios.


This entry was posted in Machine Learning. Bookmark the permalink.