📚 The CoCalc Library - books, templates and other resources
License: OTHER
From TensorFlow Official docs
Download and Setup
You can install TensorFlow using our provided binary packages or from source.
Binary Installation
The TensorFlow Python API currently requires Python 2.7: we are working on adding support for Python 3.
The simplest way to install TensorFlow is using pip for both Linux and Mac.
If you encounter installation errors, see common problems for some solutions. To simplify installation, please consider using our virtualenv-based instructions here.
Ubuntu/Linux 64-bit
Mac OS X
On OS X, we recommend installing homebrew and brew install python
before proceeding, or installing TensorFlow within virtualenv.
Docker-based installation
We also support running TensorFlow via Docker, which lets you avoid worrying about setting up dependencies.
First, install Docker. Once Docker is up and running, you can start a container with one command:
This will start a container with TensorFlow and all its dependencies already installed.
Additional images
The default Docker image above contains just a minimal set of libraries for getting up and running with TensorFlow. We also have the following container, which you can use in the docker run
command above:
b.gcr.io/tensorflow/tensorflow-full
: Contains a complete TensorFlow source installation, including all utilities needed to build and run TensorFlow. This makes it easy to experiment directly with the source, without needing to install any of the dependencies described above.
VirtualEnv-based installation
We recommend using virtualenv to create an isolated container and install TensorFlow in that container -- it is optional but makes verifying installation issues easier.
First, install all required tools:
Next, set up a new virtualenv environment. To set it up in the directory ~/tensorflow
, run:
Then activate the virtualenv:
Inside the virtualenv, install TensorFlow:
Make sure you have downloaded the source code for TensorFlow, and then you can then run an example TensorFlow program like:
Try your first TensorFlow program
(Optional) Enable GPU Support
If you installed the GPU-enabled TensorFlow pip binary, you must have the correct versions of the CUDA SDK and CUDNN installed on your system. Please see the CUDA installation instructions.
You also need to set the LD_LIBRARY_PATH
and CUDA_HOME
environment variables. Consider adding the commands below to your ~/.bash_profile
. These assume your CUDA installation is in /usr/local/cuda
:
Run TensorFlow
Open a python terminal:
Installing from sources
Clone the TensorFlow repository
--recurse-submodules
is required to fetch the protobuf library that TensorFlow depends on.
Installation for Linux
Install Bazel
Follow instructions here to install the dependencies for Bazel. Then download bazel version 0.1.1 using the installer for your system and run the installer as mentioned there:
Remember to replace PATH_TO_INSTALL.SH
to point to the location where you downloaded the installer.
Finally, follow the instructions in that script to place bazel into your binary path.
Install other dependencies
Optional: Install CUDA (GPUs on Linux)
In order to build or run TensorFlow with GPU support, both Cuda Toolkit 7.0 and CUDNN 6.5 V2 from NVIDIA need to be installed.
TensorFlow GPU support requires having a GPU card with NVidia Compute Capability >= 3.5. Supported cards include but are not limited to:
NVidia Titan
NVidia Titan X
NVidia K20
NVidia K40
Download and install Cuda Toolkit 7.0
https://developer.nvidia.com/cuda-toolkit-70
Install the toolkit into e.g. /usr/local/cuda
Download and install CUDNN Toolkit 6.5
https://developer.nvidia.com/rdp/cudnn-archive
Uncompress and copy the cudnn files into the toolkit directory. Assuming the toolkit is installed in /usr/local/cuda
:
Configure TensorFlow's canonical view of Cuda libraries
From the root of your source tree, run:
This creates a canonical set of symbolic links to the Cuda libraries on your system. Every time you change the Cuda library paths you need to run this step again before you invoke the bazel build command.
Build your target with GPU support.
From the root of your source tree, run:
Note that "--config=cuda" is needed to enable the GPU support.
Enabling Cuda 3.0.
TensorFlow officially supports Cuda devices with 3.5 and 5.2 compute capabilities. In order to enable earlier Cuda devices such as Grid K520, you need to target Cuda 3.0. This can be done through TensorFlow unofficial settings with "configure".
Known issues
Although it is possible to build both Cuda and non-Cuda configs under the same source tree, we recommend to run "bazel clean" when switching between these two configs in the same source tree.
You have to run configure before running bazel build. Otherwise, the build will fail with a clear error message. In the future, we might consider making this more conveninent by including the configure step in our build process, given necessary bazel new feature support.
Installation for Mac OS X
Mac needs the same set of dependencies as Linux, however their installing those dependencies is different. Here is a set of useful links to help with installing the dependencies on Mac OS X :
Bazel
Look for installation instructions for Mac OS X on this page.
SWIG
Notes : You need to install PCRE and NOT PCRE2.
Numpy
Follow installation instructions here.
Create the pip package and install
Train your first TensorFlow neural net model
Starting from the root of your source tree, run:
Common Problems
GPU-related issues
If you encounter the following when trying to run a TensorFlow program:
Make sure you followed the the GPU installation instructions.
Pip installation issues
Can't find setup.py
If, during pip install
, you encounter an error like:
Solution: upgrade your version of pip
:
This may require sudo
, depending on how pip
is installed.
SSLError: SSL_VERIFY_FAILED
If, during pip install from a URL, you encounter an error like:
Solution: Download the wheel manually via curl or wget, and pip install locally.
On Linux
If you encounter:
Solution: make sure you are using Python 2.7.
On MacOSX
If you encounter:
Solution: TensorFlow depends on protobuf, which requires six-1.10.0
. Apple's default python environment has six-1.4.1
and may be difficult to upgrade. There are several ways to fix this:
Upgrade the system-wide copy of
six
:Install a separate copy of python via homebrew:
Build or use TensorFlow within
virtualenv
.
If you encounter:
This is due to a conflict between protobuf versions (we require protobuf 3.0.0). The best current solution is to make sure older versions of protobuf are not installed, such as: