Installing with VirtualEnv

VirtualEnv is Virtual Environment builder for Python that creates isolated Python environments. A software installed with VirtualEnv has its own installation directories and does not interfere with other VirtualEnvs or with the OS’s Python packages. Therefore this tool addresses problems created by library dependencies, versions, permission, and so on.

Installing TensorFlow with VirtualEnv (at the beginning) simplifies the installation process especially the steps to verify the installation. Currently, the TensorFlow’s binary installation seems unstable and the first tutorial example, MNIST data, failed to work (in my case). Consequently, it is a better choice to install with VirtualEnv than to install from binary.

More resources on VirtualEnv

This page complements VirtualEnv-based installation and shows the installation process on Mac OS X El Capitan.

Step 1. Install pip and upgrade virtualenv.

$ sudo easy_install pip # If pip is not already installed
$ sudo pip install –upgrade virtualenv

Step 2. Set up a new virtual environment into directory ~/tensorflow.

$ virtualenv –system-site-packages ~/tensorflow
$ cd ~/tensorflow

Step 3. Install TensorFlow within virtualenv.

$ source bin/activate
(tensorflow)$ pip install –upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

To activate virtualenv with csh, use
$ source bin/activate.csh
instead of,
$ source bin/activate

Step 4. Verify (as presented on Try your first TensorFlow program).

$ python
>>> import tensorflow as tf
>>> hello = tf.constant(‘Hello, TensorFlow!’)
>>> quit ()
(tensorflow)$ deactivate
$

Note:
he TensorFlow tutorial suggests to run Python code convolutional.py to make sure you have downloaded the source code for TensorFlow. But this fails as follows.

(tensorflow)$ python tensorflow/models/image/mnist/convolutional.py
python: can’t open file ‘tensorflow/models/image/mnist/convolutional.py’: [Errno 2] No such file or directory
(tensorflow)$ ls
bin include lib pip-selfcheck.json
(tensorflow)$

The tutorial does not give lines of codes to download the source code. So the above command fails! (I think Google should change the tutorial.)

As a reference, the entire process on my terminal is given below. The commands typed into the terminal is highlighted in blue.

$ sudo easy_install pip
Password:
Searching for pip
Best match: pip 7.1.2
Adding pip 7.1.2 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Using /usr/local/lib/python2.7/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
$ sudo pip install –upgrade virtualenv
The directory ‘/Users/thkim/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
The directory ‘/Users/thkim/Library/Caches/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Collecting virtualenv
Downloading virtualenv-13.1.2-py2.py3-none-any.whl (1.7MB)
100% |████████████████████████████████| 1.7MB 183kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-13.1.2
$ pwd
/Users/thkim
$ virtualenv –system-site-packages ~/tensorflow
New python executable in /Users/thkim/tensorflow/bin/python2.7
Also creating executable in /Users/thkim/tensorflow/bin/python
Installing setuptools, pip, wheel…done.
$ cd ~/tensorflow/
$ ls
bin include lib
$ source bin/activate
(tensorflow)$ pip install –upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
Collecting tensorflow==0.5.0 from https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
Downloading https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl (9.8MB)
100% |████████████████████████████████| 9.8MB 47kB/s
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/site-packages (from tensorflow==0.5.0)
Requirement already up-to-date: numpy>=1.9.2 in /usr/local/lib/python2.7/site-packages (from tensorflow==0.5.0)
Installing collected packages: tensorflow
Found existing installation: tensorflow 0.5.0
Not uninstalling tensorflow at /usr/local/lib/python2.7/site-packages, outside environment /Users/thkim/tensorflow/bin/..
Successfully installed tensorflow-0.5.0
(tensorflow)$ ls
bin include lib pip-selfcheck.json

(tensorflow)$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow as tf
>>> hello = tf.constant(‘Hello, TensorFlow!’)
>>> sess = tf.Session()
can’t determine number of CPU cores: assuming 4
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4
can’t determine number of CPU cores: assuming 4
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>> quit ()
(tensorflow)$ deactivate

The tree structure of TensorFlow is given below.

$ cd ~/tensorflow/
$ tree -d
.
├── bin
├── include
│   └── python2.7 -> /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/include/python2.7
└── lib
└── python2.7
├── config -> /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
├── distutils
├── encodings -> /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings
├── lib-dynload -> /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
└── site-packages
├── _markerlib
├── external
│   ├── accessibility-developer-tools
│   │   └── dist
│   │   └── js
│   ├── async
│   │   ├── deps
│   │   ├── lib
│   │   └── support
│   ├── chai
│   ├── d3
│   ├── dagre
│   │   └── dist
│   ├── es6-promise
│   ├── font-roboto
│   ├── graphlib
│   │   └── dist
│   ├── hydrolysis
│   ├── iron-a11y-keys-behavior
│   ├── iron-ajax
│   ├── iron-autogrow-textarea
│   ├── iron-behaviors
│   ├── iron-checked-element-behavior
│   ├── iron-collapse
│   ├── iron-component-page
│   ├── iron-doc-viewer
│   ├── iron-dropdown
│   ├── iron-fit-behavior
│   ├── iron-flex-layout
│   │   └── classes
│   ├── iron-form-element-behavior
│   ├── iron-icon
│   ├── iron-icons
│   ├── iron-iconset-svg
│   ├── iron-input
│   ├── iron-list
│   │   └── test
│   │   └── smoke
│   ├── iron-menu-behavior
│   ├── iron-meta
│   ├── iron-overlay-behavior
│   ├── iron-range-behavior
│   ├── iron-resizable-behavior
│   │   └── demo
│   │   └── src
│   ├── iron-selector
│   ├── iron-validatable-behavior
│   ├── lodash
│   ├── marked
│   │   └── lib
│   ├── marked-element
│   ├── mocha
│   ├── neon-animation
│   │   ├── animations
│   │   └── demo
│   │   ├── card
│   │   ├── declarative
│   │   ├── doc
│   │   ├── dropdown
│   │   ├── grid
│   │   ├── list
│   │   ├── load
│   │   ├── reprojection
│   │   └── tiles
│   ├── paper-behaviors
│   ├── paper-button
│   ├── paper-checkbox
│   ├── paper-dropdown-menu
│   ├── paper-header-panel
│   ├── paper-icon-button
│   ├── paper-input
│   ├── paper-item
│   ├── paper-material
│   ├── paper-menu
│   ├── paper-menu-button
│   ├── paper-progress
│   ├── paper-radio-button
│   ├── paper-radio-group
│   ├── paper-ripple
│   ├── paper-slider
│   ├── paper-styles
│   │   └── classes
│   ├── paper-toggle-button
│   ├── paper-toolbar
│   ├── plottable
│   ├── polymer
│   ├── prism
│   │   ├── components
│   │   ├── plugins
│   │   │   ├── autolinker
│   │   │   ├── autoloader
│   │   │   ├── file-highlight
│   │   │   ├── highlight-keywords
│   │   │   ├── ie8
│   │   │   ├── jsonp-highlight
│   │   │   ├── keep-markup
│   │   │   ├── line-highlight
│   │   │   ├── line-numbers
│   │   │   ├── previewer-angle
│   │   │   ├── previewer-base
│   │   │   ├── previewer-color
│   │   │   ├── previewer-easing
│   │   │   ├── previewer-gradient
│   │   │   ├── previewer-time
│   │   │   ├── remove-initial-line-feed
│   │   │   ├── show-invisibles
│   │   │   ├── show-language
│   │   │   └── wpd
│   │   ├── tests
│   │   │   └── helper
│   │   ├── themes
│   │   └── vendor
│   ├── prism-element
│   ├── promise-polyfill
│   ├── sinon-chai
│   │   └── lib
│   ├── sinonjs
│   ├── six_archive
│   ├── stacky
│   │   └── lib
│   ├── svg-typewriter
│   ├── web-animations-js
│   ├── web-component-tester
│   │   └── data
│   └── webcomponentsjs
├── google
│   └── protobuf
│   ├── compiler
│   ├── internal
│   │   └── import_test_package
│   ├── pyext
│   └── util
├── pip
│   ├── _vendor
│   │   ├── _markerlib
│   │   ├── cachecontrol
│   │   │   └── caches
│   │   ├── colorama
│   │   ├── distlib
│   │   │   └── _backport
│   │   ├── html5lib
│   │   │   ├── filters
│   │   │   ├── serializer
│   │   │   ├── treeadapters
│   │   │   ├── treebuilders
│   │   │   ├── treewalkers
│   │   │   └── trie
│   │   ├── lockfile
│   │   ├── packaging
│   │   ├── pkg_resources
│   │   ├── progress
│   │   └── requests
│   │   └── packages
│   │   ├── chardet
│   │   └── urllib3
│   │   ├── contrib
│   │   ├── packages
│   │   │   └── ssl_match_hostname
│   │   └── util
│   ├── commands
│   ├── compat
│   ├── models
│   ├── operations
│   ├── req
│   ├── utils
│   └── vcs
├── pip-7.1.2.dist-info
├── pkg_resources
│   └── _vendor
│   └── packaging
├── setuptools
│   └── command
├── setuptools-18.2.dist-info
├── tensorflow
│   ├── core
│   │   ├── example
│   │   ├── framework
│   │   ├── kernels
│   │   ├── lib
│   │   │   └── core
│   │   └── util
│   ├── models
│   │   ├── image
│   │   │   ├── cifar10
│   │   │   └── mnist
│   │   └── rnn
│   ├── python
│   │   ├── client
│   │   ├── framework
│   │   ├── lib
│   │   │   ├── core
│   │   │   └── io
│   │   ├── ops
│   │   ├── platform
│   │   │   └── default
│   │   ├── summary
│   │   │   └── impl
│   │   ├── training
│   │   ├── user_ops
│   │   └── util
│   │   └── protobuf
│   ├── tensorboard
│   │   ├── dist
│   │   └── lib
│   │   └── css
│   └── tools
│   └── pip_package
├── tensorflow-0.5.0.dist-info
├── wheel
│   ├── signatures
│   ├── test
│   │   ├── complex-dist
│   │   │   └── complexdist
│   │   ├── headers.dist
│   │   └── simple.dist
│   │   └── simpledist
│   └── tool
└── wheel-0.24.0.dist-info

228 directories
$