Mac下使用源码编译安装TensorFlow CPU版本
这是安装TensorFlow CPU版本的第二种方法,第一种方法大家可以参见我的
Mac上Anaconda+Tensorflow安装这篇博文,其实探讨这种方法是因为在用第一种安装方法安装好了之后,在运行程序的时候可能会出现:
2017-07-06 22:56:18.520959: 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.
2017-07-06 22:56:18.520985: 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.
2017-07-06 22:56:18.520989: 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.
2017-07-06 22:56:18.520993: 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.
这样的错误,所以参照:TensorFlow CPU环境SSE / AVX / FMA指令集编译
这篇文章进行探索,但是问题没有解决,却突然发现这就是使用源码编译的形式来安装TensorFlow的方法,所以就还是码篇博文来分享,希望哪个大牛看到也可以顺便帮我解决一下前面这几个警告的问题。废话不多说了,下面就是安装的步骤了:
下面的步骤都是参考官方文档(放在这镇楼):
Installing TensorFlow from Sources
首先Mac下内置有gcc,可以通过终端命令:
$ gcc -v
查看,查看的结果如下:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
其中的4.2.1就是gcc的版本,或者大家也可以直接输入终端命令:
$ python
可以看到:
Python 2.7.13 |Anaconda 4.4.0 (x86_64)| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
里面有一个GCC 4.2.1,感觉比上面那个命令更直观一些。
然后就是要安装Google自家的编译工具bazel了,mac上最好的办法就是直接使用brew安装了:
$ brew install bazel
安装好之后就要下载官方的TensorFlow源码了:
$ git clone https://github.com/tensorflow/tensorflow
下载完成后会在你的用户名的目录下生成一个tensorflow的文件夹,使用
$ cd tensorflow
进入这个文件夹,然后输入:
./configure
进行配置,在配置过程中会出现一系列的问题,通常情况下没有特殊的要求,一般全部都选择n:
配置完成后就是编译过程了,输入终端命令(输入此命令后你会发现你的电脑呼呼作响,说实话还是有点小心疼啊,但是为了学习,我忍了,并且会花一段时间来编译,大家可以打一盘农药了):
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
经过漫长的编译后,任务就基本上完成了,接下来就是输入下面的命令来生成pip安装包了:
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.2.1-py2-none-any.whl
最后就是用pip命令来安装TensorFlow了:
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.2.1-py2-none-any.whl
至此就完成了。
更多推荐
所有评论(0)