How to install TensorFlow on Windows?

2020-02-02 06:07发布

I am starting to work with TensorFlow library for deep learning, https://www.tensorflow.org/.

I found a explicit guide to work on it on linux and Mac but I did not find how to work with it under Windows. I try over the net, but the information are lacking.

I use Visual Studio 2015 for my projects, and I am trying to compile the library with Visual studio Compiler VC14.

How to install it and to use it under Windows?

Can I use Bazel for Windows for production use?

11条回答
2楼-- · 2020-02-02 06:29

Following may work for you: install Virtual Box, create Linux VM and install Linux into it. I'd recommend Ubuntu, because Google often uses it internally. Then, install TensorFlow in Linux VM.

查看更多
Bombasti
3楼-- · 2020-02-02 06:30

Now Tensorflow is officially supported in Windows, you can install it using pip command of Python 3.5 without compile it yourself

CPU Version

pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0-cp35-cp35m-win_amd64.whl

cp35 indicates python 3.5 wheel, 0.12.0 the version, you can edit these according your preference, or to install latest CPU version available you can use

pip install --upgrade tensorflow

GPU Version

pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-0.12.0-cp35-cp35m-win_amd64.whl

cp35 indicates python 3.5 wheel, 0.12.0 the version, you can edit these according your preference, or to install latest GPU version available you can use

pip install --upgrade tensorflow-gpu

More Info

查看更多
女痞
4楼-- · 2020-02-02 06:31

Sorry for the excavation, but this question is quite popular, and now it has a different answer.

Google officially announced the addition of Windows (7, 10, and Server 2016) support for TensorFlow: developers.googleblog.com

The Python module can be installed using pip with a single command:

C:\> pip install tensorflow

And if you need GPU support:

 C:\> pip install tensorflow-gpu

TensorFlow manual - How to install pip on windows

Another useful information are included in release notes: https://github.com/tensorflow/tensorflow/releases

UPD: As @m02ph3u5 right mentioned in the comments TF for windows supports only Python 3.5.x Installing TensorFlow on Windows with native pip

查看更多
Fickle 薄情
5楼-- · 2020-02-02 06:31

If you have already installed anaconda on your windows, there is an easier way as I found out:

conda create --name snakes python=3

Then

activate snakes

Then

pip install tensorflow

This is similar to virtualenv and I found this helpful.

查看更多
Evening l夕情丶
6楼-- · 2020-02-02 06:33

How to install TensorFlow and to use it under Windows?

Updated on 8/4/16

Windows 10 now has a Ubuntu Bash environment, AKA Bash on Ubuntu on Windows, available as a standard option (as opposed to Insider Preview updates for developers). (StackOverflow tag wsl) This option came with the Windows 10 anniversary update (Version 1607) released on 8/2/2016. This allows the use of apt-get to install software packages such as Python and TensorFlow.

Note: Bash on Ubuntu on Windows does not have access to the GPU, so all of the GPU options for installing TensorFlow will not work.

The dated installation instructions for Bash on Ubuntu on Windows are basically correct, but only these steps are necessary:
Prerequisites
Enable the Windows Subsystem for Linux feature (GUI)
Reboot when prompted
Run Bash on Windows

Steps no longer needed:
Turn on Developer Mode
Enable the Windows Subsystem for Linux feature (command-line)

Then install TensorFlow using apt-get

sudo apt-get install python3-pip python3-dev
sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl 

and now test TensorFlow

$ python3
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>> exit()

and run an actual neural network

python3 -m tensorflow.models.image.mnist.convolutional

Earlier Answer

After learning about the developer preview of Bash on Windows.

See Playing with TensorFlow on Windows by Scott Hanselman which uses Bash on Windows 10

Original Answer

Bazel is the problem

TensorFlow is not made with build automation tools such as make, but with Google's in-house build tool Bazel. Bazel only works on systems based on Unix such as Linux and OS X.

Since the current published/known means to build TensorFlow uses Bazel and Bazel does not work on Windows, one can not install or run TensorFlow natively on Windows.

From Bazel FAQ

What about Windows?

Due to its UNIX heritage, porting Bazel to Windows is significant work. For example, Bazel uses symlinks extensively, which has varying levels of support across Windows versions.

We are currently actively working on improving Windows support, but it's still ways from being usable.

Status

See: TensorFlow issue #17
See: Bazel issue #276

Solutions

The solutions are listed in the order of complexity and work needed; from about an hour to may not even work.

  1. Docker
    ~ 1 hour

Docker installation

Docker is a system to build self contained versions of a Linux operating system running on your machine. When you install and run TensorFlow via Docker it completely isolates the installation from pre-existing packages on your machine.

Also look at TensorFlow - which Docker image to use?

  1. OS X
    ~ 1 hour

If you have a current Mac running OS X then see: Installation for Mac OS X

  1. Linux

The recommend Linux system tends to be Ubuntu 14.04 LTS (Download page).

a. Virtual Machine - Hardware Virtualization - Full Virtualization
~ 3 hours

Download and install a virtual machine such as the commercial VMware or the free Virtual Box, after which you can install Linux and then install TensorFlow.

When you go to install TensorFlow you will be using Pip - Python's package management system. Visual Studio users should think NuGet. The packages are known as wheels.

See: Pip Installation

If you need to build from the source then see: Installing From Sources
~ 4 hours

Note: If you plan on using a Virtual Machine and have never done so before, consider using the Docker option instead, since Docker is the Virtual Machine, OS and TensorFlow all packaged together.

b. Dual boot
~ 3 hours

If you want to run TensorFlow on the same machine that you have Windows and make use of the GPU version then you will most likely have to use this option as running on a hosted Virtual Machine, Type 2 hypervisor, will not allow you access to the GPU.

  1. Remote machine
    ~ 4 hours

If you have remote access to another machine that you can install the Linux OS and TensorFlow software on and allow remote connections to, then you can use your Windows machine to present the remote machine as an application running on Windows.

  1. Cloud Service
    I have no experience with this. Please edit answer if you know.

Cloud services such as AWS are being used.

From TensorFlow Features

Want to run the model as a service in the cloud? Containerize with Docker and TensorFlow just works.

From Docker

Running Docker on AWS provides a highly reliable, low-cost way to quickly build, ship, and run distributed applications at scale. Deploy Docker using AMIs from the AWS Marketplace.

  1. Wait for Bazel to work on Windows.

Currently it appears the only hold up is Bazel, however Bazel's roadmap list working on Windows should be available this year.

There are two features listed for Windows:

2016‑02  Bazel can bootstrap itself on Windows without requiring admin privileges.  

2016‑12  Full Windows support for Android: Android feature set is identical for Windows and Linux/OS X.
  1. Build TensorFlow by hand.
    A few days or more depending on you skill level. I gave up on this one; too many subprojects to build and files to locate.

Remember that Bazel is only used to build TensorFlow. If you get the commands Bazel runs and the correct source code and libraries you should be able to build TensorFlow on Windows. See: How do I get the commands executed by Bazel.

While I have not researched this more, you can look at the continuous integration info for needed files and info on how to they build it for testing. (Readme) (site)

  1. Build Bazel on Windows
    A few days or more depending on you skill level. I gave up on this one also; could not find the necessary source files needed for Windows.

There is a public experimental source code version of Bazel that boots on Windows. You may be able to leverage this into getting Bazel to work on Windows, etc.

Also these solutions require the use of Cygwin or MinGW which adds another layer of complexity.

  1. Use alternative build system such as Make
    If you get this one to work I would like to see in on GitHub.

This currently does not exist for TensorFlow. It is a feature request.

See: TensorFlow issue 380

  1. Cross Build
    If you get this one to work I would like to see in on GitHub.

You build TensorFlow on Linux using Bazel but change the build process to output a wheel that can be installed on Windows. This will require detailed knowledge of Bazel to change the configuration, and locating the source code and libraries that work with Windows. An option I would only suggest as a last resort. It may not even be possible.

  1. Run on the new Windows Subsystem for Linux.

See: Windows Subsystem for Linux Overview

You will know as much as I do by reading the referenced article.

Can I use Bazel for Windows for production use?

Since it is experimental software I would not use on a production machine.

Remember that you only need Bazel to build TensorFlow. So use the experimental code on a non production machine to build the wheel, then install the wheel on a production machine. See: Pip Installation

TLDR;

Currently I have several versions for learning. Most use a VMWare 7.1 Workstation to host Ubuntu 14.04 LTS or Ubuntu 15 or Debian. I also have one dual boot of Ubuntu 14.04 LTS on my Windows machine to access the GPU as the machine with VMware does not have the proper GPU. I would recommend that you give these machines at least 8G of memory either as RAM or RAM and swap space as I have run out of memory a few times.

查看更多
太酷不给撩
7楼-- · 2020-02-02 06:35

I managed to install TensorFlow on Win8.1 without Docker using advice from https://discussions.udacity.com/t/windows-tensorflow-and-visual-studio-2015/45636

I tried a lot of stuff before that, and i won't try to install it twice but here is what i did: - install VS2015 (make sure Visual C++ installed as well) - install Python Tools for VS2015 - install Python2.7 with Anaconda2 - install pip and conda for Python - install numpy with pip inside VS2015 - install tensorflow with pip inside VS2015

i didn't manage to do it with Python3.5

I managed also to install on Win8.1 via Cloud9 There is a video tutorial on Youtube.

https://www.youtube.com/watch?v=kMtrOIPLpR0

EDIT: actually for the above, (not Cloud9 which is fine) i have problems: TensorFlow LOOKS LIKE it's installed (i can see it in the list of modules installed in VS2015 when clicking in Solution Explorer on Python 64-bit 2.7) but if i type in a script or in Python Interactive import tensorflow as TF then i get an error message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
    from tensorflow.python.framework.framework_lib import *
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\python\framework\framework_lib.py", line 62, in <module>
    from tensorflow.python.framework.ops import Graph
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\python\framework\ops.py", line 40, in <module>
    from tensorflow.python.framework import versions
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\python\framework\versions.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "C:\Users\Fagui\Anaconda2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
    import _pywrap_tensorflow

enter image description here

查看更多
登录 后发表回答