There is guide on official site. It is not very comprehensive but is very useful.

Summary

Install Git for Microsoft Windows Install MSYS2 x64 and command line tools Install Build Tools for Visual Studio 2017 Install Bazel 0.26.1 Install Python 3.7 64-bits Install NVIDIA CUDA 10.1 and cuDNN 7.6 (for GPU acceleration) Configure build environment Clone TensorFlow v2.0.0 source code and apply mandatory patch Configure build parameters Build TensorFlow from sources Create TensorFlow wheel file for Python 3.7 Install TensorFlow wheel file for Python 3.7 and check result

Step 1: Install Git for Microsoft Windows

Download and install Git for Windows. I take it here. Be sure path to git.exe is added to %PATH% environment variable. I install Git to the

C:\Bin\Git

folder for this tutorial.

Step 2: Install MSYS2 x64 and command line tools

Download and install 64-bits distribution here. Bazel uses grep, patch, unzip and other ports of Unix-tools to build sources. You can try to find stand-alone binaries for each of them but I prefer use MSYS2 bundle. I install it to the

C:\Bin\msys64

folder for this tutorial. You have to add folder with tools to %PATH% environment variable. It is “C:\Bin\msys64\usr\bin” in my case.

Start “MSYS2 MinGW 64-bit” shortcut from Start Menu. Run the following command to update (restart “MSYS2 MinGW 64-bit” if it asks):

pacman -Syu

Then run:

pacman -Su

Install tools are necessary for build:

pacman -S patch unzip

Close “MSYS2 MinGW 64-bit” shell by “exit” command. We don’t need it any more.

Step 3: Install Build Tools for Visual Studio 2017

Build Tools for Visual Studio 2017 that ships within Visual Studio 2019 does not work for me. So I installs “Visual Studio Community 2017 (version 15.9)” from archive:

It install necessary “Microsoft Visual C++ 2017 Redistributable” automatically.

Step 4: Install Bazel

Download bazel-0.26.1-windows-x86_64.exe here. Rename the binary to bazel.exe and move it to a directory on your %PATH%, so you can run Bazel by typing bazel in any directory. See details of Bazel installation for Windows x64 in case of problems.

Add BAZEL_SH global environment variable for bash location. My path is

C:\Bin\msys64\usr\bin\bash.exe

Add BAZEL_VC global environment variable for build tool chain location:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC

Step 5: Install Python 3.7 64-bits

TensorFlow v2.0 supports both Python 3.6 and Python 3.7. They are available for download here. Choose add to PATH option during the installation.

Step 6: Install NVIDIA CUDA 10.1 and cuDNN 7.6 (for GPU acceleration)

This section is actual if you have NVIDIA Graphics Card that supports CUDA. Otherwise skip this section. See step by step installation of CUDA here if you need help. I copy-paste that guide but cut some details.

Go to https://developer.nvidia.com/cuda-downloads and download CUDA 10.1 Installer for Windows [your version]. For me, version is Windows 10.

Install it in default location with default settings but uncheck the VisualStudio integration option. It will update your GPU driver if required and reboot.

Go to run (Win + R) type cmd

The following command will check for nvcc version and insure that it is set in path environment variable.

nvcc --version

Next goto https://developer.nvidia.com/cudnn (membership is required).

After login download cuDNN v7.6 library for Windows [your version] for me Windows 10. Goto downloaded folder and extract zip file.

Go inside extracted folder and copy all files and folder from cuda folder (eg. bin, include, lib) and paste to “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0”.

Final step here is to add “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64” to %PATH% environment variable.

Step 7: Configure build environment

Start VC++2017 shell for x64 (“x64 Native Tools Command Prompt for VS 2017” shortcut) from Start Menu.

Next you have to create, activate and configure Python environment. Run inside “x64 Native Tools Command Prompt for VS 2017” shell commands below (correct paths according your locations).

python -m pip install --upgrade pip python -m venv C:\Users\amsokol\tensorflow-v2.0.0\.venv C:\Users\amsokol\tensorflow-v2.0.0\.venv\Scripts\activate.bat python -m pip install --upgrade pip pip install setuptools --upgrade

Your shell should looks like that after commands applied:

Install mandatory Python packages:

pip install six numpy wheel pip install keras_applications==1.0.8 --no-deps pip install keras_preprocessing==1.0.9 --no-deps

Run “pip list” to ensure the mandatory packages are installed:

That’s all for now. Do not close shell.

Step 8: Clone TensorFlow source code and apply mandatory patch

First of all you have to choose folder where to clone TensorFlow source code. It is “C:\Users\amsokol\tensorflow-v2.0.0” in my case. Back to shell and run:

cd C:\Users\amsokol\tensorflow-v2.0.0

Clone source code:

Checkout latest of 2.0.0 version:

cd tensorflow git checkout v2.0.0

Step 9: Configure build parameters

Ensure we are in source code root folder:

cd C:\Users\amsokol\tensorflow-v2.0.0\tensorflow

Run configurator:

python ./configure.py

First it asks location of Python. Press Enter to leave default value:

...

You have bazel 0.26.1 installed. Please specify the location of python. [Default is C:\Users\amsokol\tensorflow-v2.0.0\.venv\Scripts\python.exe]:

Then its asks location of Python library paths. Press Enter to leave default value:

Found possible Python library paths:

C:\Users\amsokol\tensorflow-v2.0.0\.venv\lib\site-packages

Please input the desired Python library path to use. Default is [C:\Users\amsokol\tensorflow-v2.0.0\.venv\lib\site-packages]

Then it asks about XLA JIT support. Press “Enter” to avoid it:

Do you wish to build TensorFlow with XLA JIT support? [y/N]:

No XLA JIT support will be enabled for TensorFlow.

Then it asks about ROCm support. We don’t need it if we choose CUDA support. Press “Enter”:

Do you wish to build TensorFlow with ROCm support? [y/N]:

No ROCm support will be enabled for TensorFlow.

Then it asks about CUDA support:

Do you wish to build TensorFlow with CUDA support? [y/N]:

Answer “y” if you are going to use GPU acceleration (otherwise press “n”):

Do you wish to build TensorFlow with CUDA support? [y/N]: y

CUDA support will be enabled for TensorFlow. Found CUDA 10.1 in:

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/lib/x64

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

Found cuDNN 7 in:

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/lib/x64

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

In case on Yes for CUDA configurator asks CUDA compute capabilities to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. I have GTX 1070 that’s why I answer 6.1:



You can find the compute capability of your device at:

Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 3.5,7.0]: 6.1 Please specify a list of comma-separated Cuda compute capabilities you want to build with.You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 3.5,7.0]:

Next question is to set optimization flags. I have 6th Gen Intel CPU that’s why I answer /arch:AVX2:

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]: /arch:AVX2

Last question is about eigen. Answer “y”. It reduces compile time dramatically.

Would you like to override eigen strong inline for some C++ compilation to reduce the compilation time? [Y/n]: y

Eigen strong inline overridden.

Configuration completed. Lets build.

Step 10: Build TensorFlow from sources

Ensure we are in source code root folder:

cd C:\Users\amsokol\tensorflow-v2.0.0\tensorflow

Build takes long time. I strongly recommend turn off antivirus software including Windows Defender Antivirus real-time protection.

Run build:

bazel build --config=opt --define=no_tensorflow_py_deps=true //tensorflow/tools/pip_package:build_pip_package

Sit back and relax for some time.

Step 11: Create TensorFlow wheel file for Python 3.7

Run command to create Python wheel file:

mkdir ..\out bazel-bin\tensorflow\tools\pip_package\build_pip_package ..\out

It creates tensorflow-2.0.0-cp37-cp37m-win_amd64.whl file in the “..\out” folder.

Step 12: Install TensorFlow wheel file for Python 3.7 and check result

Run command to install Python wheel file:

pip install ..\out\tensorflow-2.0.0-cp37-cp37m-win_amd64.whl

So lets run MNIST to ensure Tensorflow 2.0 installed successfully:

from __future__ import absolute_import, division, print_function, unicode_literals # Install TensorFlow import tensorflow as tf mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train, x_test = x_train / 255.0, x_test / 255.0 model = tf.keras.models.Sequential([

tf.keras.layers.Flatten(input_shape=(28, 28)),

tf.keras.layers.Dense(128, activation='relu'),

tf.keras.layers.Dropout(0.2),

tf.keras.layers.Dense(10, activation='softmax')

]) model.compile(optimizer='adam',

loss='sparse_categorical_crossentropy',

metrics=['accuracy']) model.fit(x_train, y_train, epochs=5) model.evaluate(x_test, y_test, verbose=2)

My output is

You have successfully installed TensorFlow v2.0 on Windows machine.

Do let me know in the comments below if it worked for you. Or if you got any errors. Thanks!