Nov 21, 2017 TensorFlow – Quick Guide of installing TensorFlow on Mac using VirtualEnv Posted on November 21, 2017 November 22, 2017 by Robin Leave a comment AI.
TensorFlow is the Google built open source software library for machine intelliegence.
Per Google: TensorFlow is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them.
This article assumes that you have a basic knowledge of the terminal, node, homebrew, and the command line -- and that you are working on a Mac (directions could be adjusted for a PC, but that's not what they're written for).This article also assumes that you do not have a working knowledge of python or anaconda.
Check your version of python:
$ python --version
If it is not 3.5, download and install it from here
Install Dependencies:
$ brew install bazel swig
$ sudo easy_install -U six
$ sudo easy_install -U numpy
$ sudo easy_install wheel
$ sudo easy_install ipython
Installing Anaconda
- Go to continuum to download the Anaconda CLI installerDownload Command-Line Installer for Python 3.5
$ cd [downloaded file location -- most likely Downloads]
$ bash FILENAME
$ cd
$ vim .zshrc (or .bash_profile)
From vim add export PATH='$HOME/anaconda3/bin:$PATH'
to your .zshrc or .bash_profile file, then exit vim.
$ conda install -c conda-forge tensorflow
(where NAME = the name you give your environment)
$ conda create —n NAME python=3.5
$ source activate NAME
(at the end $ source deactivate
to exit)
Other helpful Anaconda Commands:
- List your environments:
$ conda info —-envs
- What Anaconda Version?
$ conda info —-version
- Help:
$ conda info —h
- Remove an environment:
conda-env remove -n NAME
Then to test it…
$ source activate NAME
$ ipython
[1]: import tensorflow as tf
[2]: <blank> the fact that nothing shows up here is good
then..
[2]: exit
After exiting OR instead of using ipython:
$ jupyter notebook
(pick a folder or create one then create a notebook)
In the first text line of the notebook:import tensorflow as tf
In the top menu bar go to cell > run all. You should see no errors -- that's good!
Next you can test whatever you want, for example — the small python code segment from the tensorflow site:
Copy and Paste this entire script into your jupyter notebook file
In the top menu bar go to cell > run all — and your result will be calculated in the bottom of the notebook.
Special thanks to a data scientist friend and some willing test subjects to work out the kinks in this process.
System information
Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
MacOX Yosemite 10.10.5TensorFlow installed from (source or binary):
source (binary loads fine, no problem)TensorFlow version (use command below):
Tensorflow 1.4.1Python version:
Python 2.7.14Bazel version (if compiling from source):
0.9.0GCC/Compiler version (if compiling from source):
Xcode7.2.1CUDA/cuDNN version:
N/aGPU model and memory:
N/aExact command to reproduce:
See my notes for TensorFlow 1.4.1 install from source below.. Note: Bazel build completed successfully, only issue is the failure to 'pip install ..' the wheel file.
Describe the problem
< see the tl:dr at bottom of notes..>
Can't load generated wheel file of Tensorflow 1.4.1 into Python 2.7.14, despite having built everything local. Tried with several Python versions, MacOS orginal version, Python 2.7.14 (from binary upgrade), and using a Python 2.7.14 that I built an installed locally. Note: Tensorflow 1.4.0 binary can be loaded and runs ok (but operates differently than TensorFlow 1.4.0 that I have running on CentOS-7.4 box, hence my interest in building from source, and tracking down why this is the case
Source code / logs
Bazel Build was ok, built for CPU only , 4044 actions, successful completion. Also the build_pip_package works fine. Only issue is the failure to pip install the wheel file
Here are notes of exactly what I did..
Done on Macbook, Yosemite 10.10.5, using Xcode-7.2.1
You need to get Xcode7.2.1 from Apple and install it.
For TensorFlow build using Bazel you need to install:
First tried with: Xcode6.3.x (needed to put DOSbox on iPad as DOSpad)
Had to update Xcode. After Xcode7.2.1 install (copy .dmg to /Applications/Xcode7.2.1)
Note the directory had to be manually created first.
Run it all as root on the Macbook..
cd /home/TensorFlow/tensorflow-1.4.1
Needed to do a 'make clean' in Bazel. Do this:
bazel clean --expunge (pitche le vache.. totemo, eh?)
Run this to build..
Note: the ./configure is a Q&A. For initial build, no special features were
selected (ie. I selected 'n' to all the 'build with this cool thing? (Y/n): ' )
Once configure is complete, do this.. (note, it is all one line..)
//tensorflow/tools/pip_package:build_pip_package
The build runs for 66 minutes, and reports:
This makes a build_pip_package.sh file in the ./tensorflow/tools/pip_package subdir.
You now need to make the .whl (the compressed package pip uses to install to python)
from this thing the Bazel build made. You run the script: 'bazel-bin' to do this.
On the Macbook (and Linux), you will need to enter: 'bazel-bin/tensorflow.. '
for it to work.
Note: 'pwd' reports: '/home/TensorFlow/tensorflow-1.4.1
Note: The TensorFlow build instructions use top level directory '/tmp', but I
don't want it destroyed if it works. (/tmp means 'temporary', eh?)
I created top level '/tftop'
Note: 'bazel-bin' is a directory. You are running the 'build_pip_package' script
that is down in there, not the build_pip_package.sh script in ./tensorflow tree.
' ./bazel-bin/tensorflow/tools/pip_package/build_pip_package: No such file or directory'
tensorflow-1.4.1-cp27-cp27m-macosx_10_4_x86_64.whl is not a supported wheel on this platform
Marshall mathers lp download zip. What I did:
'tensorflow-1.4.1-cp27-cp27m-macosx_10_4_x86_64.whl is not a supported wheel on this platform'
Result: TensorFlow Build successful, 'pip install ..' to Python 2.7.14 on MacOSX
fails with version mis-match. (? or a bug maybe ?)
I was expecting the documentation to match this install process.
I probably need the '-py2-none-any.whl' type of wheel to be generated, right?
What I am getting is some very MacOSX version-specific thing being built, which
is failing the 'pip install ..' because of a version-mismatch, maybe.
TL;DR: How can I force the build process to build the '-py2-none-any.whl' type of wheel (which
does not have fascist-style version-checking (:D), and just builds the .whl file as per
what the TensorFlow build instructions describe?
or
Is there some tweak I can make to the build process (which all seems to be working quite fine),
to tell the process to really, actually, please code the built version of TensorFlow 1.4.1, to
the actual machine (the Yosemite 10.10.5 Macbook), that I have run the build upon??
- Mark Langdon, Jan. 5, 2018