找回密码
 立即注册

QQ登录

只需一步,快速开始

作者

2569

主题

2577

帖子

9517

积分

爱咖骏神

Rank: 9Rank: 9Rank: 9

积分
9517

在Ubuntu上安装TensorFlow

0 331
Heinilup 发表于 2017-4-18 10:34:26 |阅读模式 |复制链接
在Ubuntu上安装TensorFlow
Installing TensorFlow on Ubuntu            
    This guide explains how to install TensorFlow on Ubuntu. These instructionsmight also work on other Linux variants, but we have only tested (and weonly support) these instructions on Ubuntu 14.04 or higher.

此说明为官方安装说明:

Determine which TensorFlow to installYou must choose one of the following types of TensorFlow to install:
  • 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.
  • 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.

NVIDIA requirements to run TensorFlow with GPU supportIf you are installing TensorFlow with GPU support using one of themechanisms described in this guide, then the following NVIDIA softwaremust 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    LD_LIBRARY_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.    Ensure that you create the CUDA_HOME environment variable as    described in the NVIDIA documentation.
  • GPU card with CUDA Compute Capability 3.0 or higher.  See    NVIDIA documentation for    a list of supported GPU cards.
  • The libcupti-dev library, which is the NVIDIA CUDA Profile Tools Interface.    This library provides advanced profiling support. To install this library,    issue the following command:
    $ sudo apt-get install libcupti-dev
If you have an earlier version of the preceding packages, please upgrade tothe specified versions. If upgrading is not possible, then you may still runTensorFlow with GPU support, but only if you do the following:
  • Install TensorFlow from sources as documented in    Installing TensorFlow from Sources.
  • Install or upgrade to at least the following NVIDIA versions:
    • CUDA toolkit 7.0 or greater
    • cuDNN v3 or greater
    • GPU card with CUDA Compute Capability 3.0 or higher.
Determine how to install TensorFlow

You must pick the mechanism by which you install TensorFlow. Thesupported choices are as follows:

We recommend the virtualenv installation.

Virtualenvis a virtual Python environment isolated from other Python development,incapable of interfering with or being affected by other Python programson the same machine.  During the virtualenv installation process,you will install not only TensorFlow but also all the packages thatTensorFlow requires.  (This is actually pretty easy.)To start working with TensorFlow, you simply need to "activate" thevirtual environment.  All in all, virtualenv provides a safe andreliable mechanism for installing and running TensorFlow.
Native pip installs TensorFlow directly on your system without goingthrough any container system. We recommend the native pip install forsystem administrators aiming to make TensorFlow available to everyone on amulti-user system. Since a native pip installation is not walled-off ina separate container, the pip installation might interfere with otherPython-based installations on your system. However, if you understand pipand your Python environment, a native pip installation often entails onlya single command.
Docker completely isolates the TensorFlow installationfrom pre-existing packages on your machine. The Docker container containsTensorFlow and all its dependencies. Note that the Docker image can be quitelarge (hundreds of MBs). You might choose the Docker installation if you areincorporating TensorFlow into a larger application architecture that alreadyuses Docker.
In Anaconda, you may use conda to create a virtual environment.However, within Anaconda, we recommend installing TensorFlow with thepip install command, not with the conda install command.
NOTE: The conda package is community supported, not officially supported.That is, the TensorFlow team neither tests nor maintains the conda package.Use that package at your own risk.

Installing with virtualenv
Take the following steps to install TensorFlow with Virtualenv:
  • Install pip and virtualenv by issuing the following command:
    1. $ sudo apt-get install python-pip python-dev python-virtualenv
    复制代码

  • Create a virtualenv environment by issuing the following command:
    1. $ virtualenv --system-site-packages targetDirectory The targetDirectory
    复制代码

    specifies the top of the virtualenv tree.  Our instructions assume that targetDirectory is ~/tensorflow, but you may choose any directory.
  • Activate the virtualenv environment by issuing one of the following     commands:
    1. $ source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
    2. $ source ~/tensorflow/bin/activate.csh  # csh or tcshThe preceding source command should change
    复制代码

    your prompt to the following:
    1. (tensorflow)$
    复制代码

  • Issue one of the following commands to install TensorFlow in the active     virtualenv environment:
    1. (tensorflow)$ pip install --upgrade tensorflow      # for Python 2.7

    2. (tensorflow)$ pip3 install --upgrade tensorflow     # for Python 3.n

    3. (tensorflow)$ pip install --upgrade tensorflow-gpu  # for Python 2.7 and GPU

    4. (tensorflow)$ pip3 install --upgrade tensorflow-gpu # for Python 3.n
    复制代码

    and GPUIf the preceding command succeeds, skip Step 5. If the preceding command fails, perform Step 5.
  • (Optional) If Step 4 failed (typically because you invoked a pip version     lower than 8.1), install TensorFlow in the active virtualenv environment     by issuing a command of the following format:
    1. (tensorflow)$ pip install --upgrade TF_PYTHON_URL   # Python 2.7

    2. (tensorflow)$ pip3 install --upgrade TF_PYTHON_URL  # Python 3.N
    复制代码

    where TF_PYTHON_URL identifies the URL of the TensorFlow Python package. The appropriate value of TF_PYTHON_URLdepends on the operating system, Python version, and GPU support. Find the appropriate value for TF_PYTHON_URL for your system here.  For example, if you are installing TensorFlow for Linux, Python 2.7, and CPU-only support, issue the following command to install TensorFlow in the active virtualenv environment:
    1. (tensorflow)$ pip3 install --upgrade \ https://storage.googleapis.com/t ... 4m-linux_x86_64.whl
    复制代码

If you encounter installation problems, seeCommon Installation Problems.
Next StepsAfter installing TensorFlow,validate the installation.
Note that you must activate the virtualenv environment each time youuse TensorFlow. If the virtualenv environment is not currently active,invoke one of the following commands:
$ source ~/tensorflow/bin/activate      # bash, sh, ksh, or zsh $ source ~/tensorflow/bin/activate.csh  # csh or tcshWhen the virtualenv environment is active, you may runTensorFlow programs from this shell.  Your prompt will becomethe following to indicate that your tensorflow environment is active:
(tensorflow)$ When you are done using TensorFlow, you may deactivate theenvironment by invoking the deactivate function as follows:
(tensorflow)$ deactivate The prompt will revert back to your default prompt (as defined by thePS1 environment variable).
Uninstalling TensorFlowTo uninstall TensorFlow, simply remove the tree you created.For example:
$ rm -r targetDirectory
Installing with native pipYou may install TensorFlow through pip, choosing between a simpleinstallation procedure or a more complex one.
Note: TheREQUIRED_PACKAGES section of setup.pylists the TensorFlow packages that pip will install or upgrade.
Prerequisite: Python and PipPython is automatically installed on Ubuntu.  Take a moment to confirm(by issuing a python -V command) that one of the following Pythonversions is already installed on your system:
  • Python 2.7
  • Python 3.3+
The pip or pip3 package manager is usually installed on Ubuntu.  Take amoment to confirm (by issuing a pip -V or pip3 -V command)that pip or pip3 is installed.  We strongly recommend version 8.1 or higherof pip or pip3.  If Version 8.1 or later is not installed, issue thefollowing command, which will either install or upgrade to the latestpip version:
$ sudo apt-get install python-pip python-devInstall TensorFlowAssuming the prerequisite software is installed on your Linux host,take the following steps:
  • Install TensorFlow by invoking one of the following commands:
    $ pip install tensorflow      # Python 2.7; CPU support (no GPU support) $ pip3 install tensorflow     # Python 3.n; CPU support (no GPU support) $ pip install tensorflow-gpu  # Python 2.7;  GPU support $ pip3 install tensorflow-gpu # Python 3.n; GPU support If the preceding command runs to completion, you should now validate your installation.
  • (Optional.) If Step 1 failed, install the latest version of TensorFlow     by issuing a command of the following format:
    $ sudo pip  install --upgrade TF_PYTHON_URL   # Python 2.7 $ sudo pip3 install --upgrade TF_PYTHON_URL   # Python 3.N where TF_PYTHON_URL identifies the URL of the TensorFlow Python package. The appropriate value of TF_PYTHON_URLdepends on the operating system, Python version, and GPU support. Find the appropriate value for TF_PYTHON_URL for your system here.  For example, if you are installing TensorFlow for Linux, Python version 3.4, and CPU-only support, issue the following command:
    $ sudo pip3 install --upgrade \ https://storage.googleapis.com/t ... 4m-linux_x86_64.whl If this step fails, see Common Installation Problems.
Next StepsAfter installing TensorFlow, validate your installation.
Uninstalling TensorFlowTo uninstall TensorFlow, issue one of following commands:
$ sudo pip uninstall tensorflow  # for Python 2.7$ sudo pip3 uninstall tensorflow # for Python 3.n


回复

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

逛了这么久“爱咖比”,何不进去瞧瞧!

登录 发布 快速回复 返回顶部 返回列表