Introduction
The TensorFlow Python API currently supports Python 2.7 and Python 3.3+ from source.This tutorial supports a virtualenv of Tensorflow on Mac OS X (10.10.5) and Ubuntu 15.04.
Pip Installs Packages
pip is a package management system used to install and manage software packages written in Python.Python comes with easy_install (2004). pip is a later alternative (2008), and introduced the idea of requirements files (pip freeze > requirements.txt) which gives users the ability to easily replicate environments (a de-facto POM file for Maven developers). Reference #4 gives a good breakdown on easy_install vs pip.
We can use easy_install to install pip:
sudo easy_install pip
Virtual Environments
virtualenv allows multiple Python projects that have different (and often conflicting) requirements, to coexist on the same computer.We can use pip to install virtualenv:
$ sudo pip install --upgrade virtualenv
then create the virtual environment:
virtualenv --system-site-packages ~/tensorflow
and finally, activate it:
~/workspaces/public/skflow$ source ~/tensorflow/bin/activate (tensorflow)~/workspaces/public/skflow$
To exit the virtualenv at any time, type:
$ (tensorflow)~/workspaces/public/skflow$ deactivate $ ~/workspaces/public/skflow$
Installing Tensorflow into the Virtual Environment
TensorFlow is a C++ library with a Python layer for configuring its internal graph.Execute either of the following commands within the virtualenv:
Installing on Mac OS X, CPU only:
$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py2-none-any.whl
for Ubuntu (GPU enabled):
The official documentation will have the latest URLs and versions for installing Tensorflow.$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl
Installing Skflow (Optional)
Skflow is a simplified interface for TensorFlow.Within the virtualenv, type:
$ pip install -U scikit-learn $ pip install git+git://github.com/google/skflow.git
$ pip install -U pandas
Testing the Installation
Run a simple application to ensure the installation was successful.Sample Python Program:
import tensorflow as tf a = tf.constant(6) b = tf.constant(7) sess = tf.Session() print(sess.run(a * b))
Desired Output:
(tensorflow)~/workspaces/public/skflow$ python test_tf.py I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 8 I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 8 42
References
- [Sitepoint] Virtual Environments Made Easy
- [Official Docs] Python Virtualenvs
- [Blog] Introduction to Pip and Virtual Environments
- [Official Docs] Pip and easy_install
- [Official Docs] Tensorflow Docs
- [Github] Skflow