首先从git拉取源码:
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
cd tensorflow
安装依赖:
sudo pip install six numpy wheel
如果之前安装官方安装教程在线安装过,依赖程序就已经安装了,这里就不需要安装了brew install bazel
然后运行配置程序
./configure
此处在我电脑上报错了:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_144`
-v后面是安装的jdk的版本
bazel build -c opt --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package
其中参数--copt配置的是相关指令集的支持,依次是SSE4.2、AVX、AVX2、FMA
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
这里就已经告诉你可以支持哪些指令集了,全部添加就是了
bazel-bin/tensorflow/tools/pip_package/build_pip_package ./tensorflow_pkg
#卸载已经安装的
sudo pip uninstall tensorflow
#安装
sudo pip install tensorflow_pkg/tensorflow-1.3.0-cp36-cp36m-macosx_10_13_x86_64.whl