Installing TensorFlow on Windows(在Windows上安装TensorFlow)

This guide explains how to install TensorFlow on Windows.

这个向导解释了如何在windows上安装TensorFlow

Determine which TensorFlow to install(决定安装哪一个版本的TensorFlow)

You must choose one of the following types of TensorFlow to install:

您必须从下面的版本中选择一个TensorFlow版本进行安装:

  • TensorFlow with CPU support only. If your system does not have a NVIDIA® GPU, you must install this version. Note that this version of TensorFlow is typically much easier to install (typically, in 5 or 10 minutes), so even if you have an NVIDIA GPU, we recommend installing this version first.
    CPU运行TensorFlow,如果你的系统没有NVIDIA显卡内存,你就必须安装这个版本.注意这个版本安装非常的简单(通常5-10分钟时间即可),所以,即使您有NVIDIA GPU,我们也推荐您安装这个版本。
  • TensorFlow with GPU support. TensorFlow programs typically run significantly faster on a GPU than on a CPU. Therefore, if your system has a NVIDIA® GPU meeting the prerequisites shown below and you need to run performance-critical applications, you should ultimately install this version.
    GPU运行版本,TensorFlow程序在GPU上运行明显比在CPU上运行快,因此,如果你的系统有NVIDIA GPU,正好符合下面的安装要求,并且您也需要高性能的运行您的程序,您最后应该安装这个版本。

Requirements to run TensorFlow with GPU support(安装GPU版本TensorFlow的运行环境)

If you are installing TensorFlow with GPU support using one of the mechanisms described in this guide, then the following NVIDIA software must be installed on your system:

  • CUDA® Toolkit 8.0. For details, see NVIDIA’s documentation Ensure that you append the relevant Cuda pathnames to the %PATH% environment variable as described in the NVIDIA documentation.
  • The NVIDIA drivers associated with CUDA Toolkit 8.0.
  • cuDNN v5.1. For details, see NVIDIA’s documentation. Note that cuDNN is typically installed in a different location from the other CUDA DLLs. Ensure that you add the directory where you installed the cuDNN DLL to your %PATH%environment variable.
  • GPU card with CUDA Compute Capability 3.0 or higher. See NVIDIA documentation for a list of supported GPU cards.

If you have an earlier version of the preceding packages, please upgrade to the specified versions.

Determine how to install TensorFlow(决定如何安装TensorFlow)

You must pick the mechanism by which you install TensorFlow. The supported choices are as follows:
您必须选择一个安装途径,TensorFlow支持下面两种途径:

  • “native” pip
  • Anaconda

Native pip installs TensorFlow directly on your system without going through a virtual environment. Since a native pip installation is not walled-off in a separate container, the pip installation might interfere with other Python-based installations on your system. However, if you understand pip and your Python environment, a native pip installation often entails only a single command! Furthermore, if you install with native pip, users can run TensorFlow programs from any directory on the system.
使用pip直接在你的本地操作系统中安装TensorFlow不需要通过虚拟环境.因为pip本地安装不是基于分离容器的。pip安装方式也许会影响到您系统其他基于Python的安装程序。不管怎样,如果你熟悉pip和Python环境,本地pip安装通常只需要一行简单的命令。如果你使用了本地pip安装,用户可以在系统任何目录下直接运行TensorFlow程序。

 

In Anaconda, you may use conda to create a virtual environment. However, within Anaconda, we recommend installing TensorFlow with the pip install command, not with the conda install command.

使用Anaconda,你需要使用conda来创建虚拟环境,然而,在Anaconda环境里面,我们推荐使用pip install命令安装TensorFlow,而不要使用conda install命令.

NOTE: The conda package is community supported, not officially supported. That is, the TensorFlow team neither tests nor maintains this conda package. Use that package at your own risk.

注意:conda安装包是基于社区开发的,而不是官方开发的.换句话说就是TensorFlow团队没有测试和维护这个conda安装包.使用这个包需要自己控制风险.

Installing with native pip

If the following version of Python is not installed on your machine, install it now:

TensorFlow only supports version 3.5.x of Python on Windows. Note that Python 3.5.x comes with the pip3 package manager, which is the program you’ll use to install TensorFlow.

To install TensorFlow, start a terminal. Then issue the appropriate pip3 install command in that terminal. To install the CPU-only version of TensorFlow, enter the following command:

C:\> pip3 install --upgrade tensorflow

To install the GPU version of TensorFlow, enter the following command:

C:\> pip3 install --upgrade tensorflow-gpu

Installing with Anaconda

The Anaconda installation is community supported, not officially supported.

Take the following steps to install TensorFlow in an Anaconda environment:

  1. Follow the instructions on the Anaconda download site to download and install Anaconda.
  2. Create a conda environment named tensorflow by invoking the following command:
    C:> conda create -n tensorflow
  3. Activate the conda environment by issuing the following command:
    C:> activate tensorflow
     (tensorflow)C:>  # Your prompt should change
  4. Issue the appropriate command to install TensorFlow inside your conda environment. To install the CPU-only version of TensorFlow, enter the following command:
    (tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.0-cp35-cp35m-win_x86_64.whl

    To install the GPU version of TensorFlow, enter the following command (on a single line):

    (tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.0.0-cp35-cp35m-win_x86_64.whl

Validate your installation

Validate your TensorFlow installation by doing the following:

  1. Start a terminal.
  2. If you installed through Anaconda, activate your Anaconda environment.
  3. Inside that terminal, invoke python:
    C:> python
  4. Enter the following short program inside the python interactive shell:
    >>> import tensorflow as tf

    hello = tf.constant(‘Hello, TensorFlow!’)sess = tf.Session()print(sess.run(hello))

    If the Python program outputs the following, then the installation is successful and you can begin writing TensorFlow programs. (If you are new to TensorFlow, see Getting Started with TensorFlow.)

    Hello, TensorFlow!

    If the system generates an error message instead of a greeting, see the next section.

Common installation problems

We are relying on Stack Overflow to document TensorFlow installation problems and their remedies. The following table contains links to Stack Overflow answers for some common installation problems. If you encounter an error message or other installation problem not listed in the following table, search for it on Stack Overflow. If Stack Overflow doesn’t show the error message, ask a new question about it on Stack Overflow and specify the tensorflow tag.

Stack Overflow Link Error Message
41007279
[...\stream_executor\dso_loader.cc] Couldn't open CUDA library nvcuda.dll
41007279
[...\stream_executor\cuda\cuda_dnn.cc] Unable to load cuDNN DSO
42006320
ImportError: Traceback (most recent call last):
File "...\tensorflow\core\framework\graph_pb2.py", line 6, in 
from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor'
42011070
No module named "pywrap_tensorflow"

本文只是对TensorFlow官网指南进行了翻译,翻译水平有限,有问题请练习我指出。

如果这篇翻译,对您有帮助,请在评论中回复您的想法,您的支持是我最大的动力。