2019-01-17    Share on: Twitter | Facebook | HackerNews | Reddit

How to Install TensorFlow and Keras on Windows 10

Guide on how to install TensorFlow cpu-only version - the case for machines without GPU supporting CUDA. Step-by-step procedure starting from creating conda environment till testing if TensorFlow and Keras Works.

EDIT 2021: This post is partially depreciated by now since for TensorFlow 2.x CPU and GPU versions are integrated - there is no separate install and Keras is integrated with TensorFlow - no need to install separately unless you have good reasons for separate install.

Quick guide on how to install TensorFlow cpu-only version - the case for machines without GPU supporting CUDA.

Creating Conda environment for working with TensorFlow and Keras

Open anaconda prompt (hit Win+Q, type anaconda) and create conda virtualenv:

conda create -n tf_windows python=3.6

this will create minimal environement

When the environment is created, activate it. After that the environment’s name will be added before the prompt.

activate tf_windows

Installing TensorFlow

Then install TensorFlow for CPU-only machines:

(tf_windows)> pip install tensorflow

There can be few variants of the tensorflow package installation. If you need to run pip behind corporate proxy, add proxy information:

(tf_windows)> pip --proxy="proxy_url:port" install tensorflow

If you need GPU-enabled version (and your machine supports it)

(tf_windows)> pip install tensorflow-gpu

To test if installation was successful, you might want to do check:

(tf_windows)>python
>>> import tensorflow as tf
>>> sess = tf.Session()
>>> print(sess.run(tf.constant('Hello world!')))

if everything was installed correctly, you should see:

b'Hello world!''

On my machine I got warning when starting a new session:

2019-01-17 07:09:01.477724: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

Don't get scared by that, TensorFlow works, the information displayed means that it isn't as fast as it could be. In order to suppress this you will need to build TensorFlow from sources using appropriate flags (see StackOverflow answer) for compilation otherwise you can ignore it.

Installing Keras

The way that worked for me was:

(tf_windows)>conda install mingw libpython
(tf_windows)>pip install --upgrade keras

Using the --upgrade flag ensures that the latest version of Keras will be installed.

Perform the test if Keras was installed correctly

>>> from keras import backend
Using TensorFlow backend.
>>> print(backend._BACKEND)
tensorflow
>>>

Any comments or suggestions? Let me know.

To cite this article:

@article{Saf2019How,
    author  = {Krystian Safjan},
    title   = {How to Install TensorFlow and Keras on Windows 10},
    journal = {Krystian's Safjan Blog},
    year    = {2019},
}