s

ubuntu16.04 install tensorflow


2 determine which TensorFlow to install

I use TensorFlow with CPU support only.

3 Determine how to install TensorFlow

I use virtualenv

4 install with virtualenv

  • Install pip and virtualenv by issuing one of the following commands
$ sudo apt-get install python-pip python-dev python-virtualenv # for Python 2.7
 $ sudo apt-get install python3-pip python3-dev python-virtualenv # for Python 3.n
              
  • Create a virtualenv environment by issuing one of the following commands:
$ virtualenv --system-site-packages targetDirectory # for Python 2.7
 $ virtualenv --system-site-packages -p python3 targetDirectory # for Python 3.n
              

where 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:
$ source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
 $ source ~/tensorflow/bin/activate.csh  # csh or tcsh
              

The preceding source command should change your prompt to the following:

(tensorflow)$
              
  • Ensure pip ≥8.1 is installed:
(tensorflow)$ easy_install -U pip
              
  • Issue one of the following commands to install TensorFlow in the active virtualenv environment:
(tensorflow)$ pip install --upgrade tensorflow      # for Python 2.7
 (tensorflow)$ pip3 install --upgrade tensorflow     # for Python 3.n
 (tensorflow)$ pip install --upgrade tensorflow-gpu  # for Python 2.7 and GPU
 (tensorflow)$ pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU
              

5 Next Steps

After installing TensorFlow, validate the installation.

Note that you must activate the virtualenv environment each time you use
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 tcsh
              

When the virtualenv environment is active, you may run TensorFlow programs
from this shell. Your prompt will become the following to indicate that your
tensorflow environment is active:

(tensorflow)$
              

When you are done using TensorFlow, you may deactivate the environment by
invoking the deactivate function as follows:

(tensorflow)$ deactivate
              

The prompt will revert back to your default prompt (as defined by the PS1
environment variable).

6 Uninstalling TensorFlow

To uninstall TensorFlow, simply remove the tree you created. For example:

$ rm -r targetDirectory