Build TensorFlow on Windows


  1. GIT for Windows:
  2. SWIG:
  3. Visual Studio 2015:,
  4. CMake 3.4 or higher:
  5. Python 3.5 Anaconda x64:
  6. CUDA 8.0:
  7. cuDNN v5.1:


  1. Install Cmake and add it to system path.
  2. Install CUDA v8.0 (For GPU support only)
  3. Extract cuDNN (For GPU Support only)
    • copy all files from bin folder to 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin'
    • similarly from include to 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include' 
    • and 'lib\x64' to  ''C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64'.
  4. Install Anaconda in "C:\tools\", make sure you select Register Anaconda as system path for Python 3.5.
  5. Extract SWIG in "C:\tools\" folder.
  6. Open command window in the desired folder "D:\Downloads\tensorflow" (Shift+RightClick and Open Command Window here).
  7. Enter the following commands
    D:\Downloads>call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
  8. Clone tensorflow directory and set up cmake configuration:
    D:\Downloads> git clone
    D:\Downloads> cd tensorflow
    D:\Downloads\tensorflow> git checkout r1.2
    D:\Downloads\tensorflow> cd tensorflow\contrib\cmake
    D:\Downloads\tensorflow\tensorflow\contrib\cmake> mkdir build
    D:\Downloads\tensorflow\tensorflow\contrib\cmake> cd build
  9. Invoke CMake and create Visual Studio solution by entering the following commands
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release ^
     More? -DSWIG_EXECUTABLE=C:/tools/swigwin-3.0.10/swig.exe ^
     More? -DPYTHON_EXECUTABLE=C:/tools/Anaconda3/python.exe ^
     More? -DPYTHON_LIBRARIES=C:/tools/Anaconda3/libs/python35.lib ^
     More? -Dtensorflow_ENABLE_GPU=ON ^
     More? -DCUDNN_HOME="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0" 
  10. Build C++ tensorflow example
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> MSBuild /p:Configuration=Release tf_tutorials_example_trainer.vcxproj
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> Release\tf_tutorials_example_trainer.exe
  11. Build PIP package as .whl file
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> MSBuild /p:Configuration=Release tf_python_build_pip_package.vcxproj
  12. PIP package is built in .\tf_python\dist folder. Enter the following commands to install tensorflow for python
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> cd tf_python\dist
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build\tf_python\dist> pip install tensorflow_gpu-1.2.1-cp35-cp35m-win_amd64
  13. Enter the following commands to run tensorflow using python
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build\tf_python\dist> python
     >>> import tensorflow as tf
     >>> hello = tf.constant('Hello, TensorFlow!')
     >>> sess = tf.Session()
     >>> print(
     'Hello, TensorFlow!'
  14. The command should print 'Hello, TensorFlow!' if you have successfully installed tensorflow.



  1. Hi Shan,

    Thank you very much for the post, its very helpful. I did all the steps but at the end I didn't see any .whl file generated. do you have any advise on what may I be missing?

    Thank you very much

    1. Did you build for python? Do you have a compatible version of python installed on your machine?


Post a Comment

Popular posts from this blog

Build caffe, pycaffe and matcaffe on Windows

Running Tensorboard on Windows