How to build TensorFlow on macOS20 May 2017
I tried to build TensorFlow on my macOS. It was not difficult for me as a result. I could build the TensorFlow according to the official instruction. So I’ll add the tiny tips for building TensorFlow in addition to original instruction.
Clone the repository
First you need to download the source code of TensorFlow. I downloaded TensorFlow under
GOPATH because it includes Go binding package
in the repository.
We can make use of Go infrastructures by installing here. (e.g. IDE plugins). So I recommend to install under
You need to install these dependencies first.
- Python package
$ pyenv install anaconda3-4.2.0
It already includes required packages. Please try pyenv and anaconda for your Python environment. And you can install core utils with Homebrew.
$ brew install coreutils
Set configuration for building environment.
$ /path/to/tensorflow $ ./configure
- Python path ->
- Python library path (default) ->
- MKL support -> No
- optimization flag -> default
- GCP support -> No
- HDFS support -> No
- XLA compiler support -> No
- VERBS support -> No
- OpenCL support -> No
- CUDA support -> No
In order to make compilation time shorter and avoid unnecessary build error, I disabled almost all configurations. If you want, please enable them with installing corresponding dependencies.
Build and Install
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
It requires a lot of RAM and takes several minutes. The command generates the script for packaging. It puts the
.whl package under
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
You can install the package in your Python environment as ordinal Python packages.
$ pip install /tmp/tensorflow_pkg/tensorflow-1.1.0-py2-none-any.whl
Validate the installation
NOTE: Please move other workspace from the tensorflow repository otherwise you will see
not found package error.
>>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello))