Mac下Tensorflow的安装

作者: 引线小白-本文永久链接:http://www.limoncc.com/工程实践/2017-05-04-Mac下Tensorflow的安装/
知识共享许可协议: 本博客采用署名-非商业-禁止演绎4.0国际许可证

一、用conda创建tensorflow

1、库源问题

参照官方说明我们在anaconda环境下,用conda来安装tensorflow。结果遇到源无法连接的情况。所谓源的概念请参考iphone越狱你添加软件源的情形。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
➜  ~ cd anaconda
➜ anaconda sudo conda create -n tensorflow
Password:
Fetching package metadata ....
WARNING: The remote server could not find the noarch directory for the
requested channel with url: http://pypi.douban.com

It is possible you have given conda an invalid channel. Please double-check
your conda configuration using `conda config --show`.

If the requested url is in fact a valid conda channel, please request that the
channel administrator create `noarch/repodata.json` and associated
`noarch/repodata.json.bz2` files, even if `noarch/repodata.json` is empty.
$ mkdir noarch
$ echo '{}' > noarch/repodata.json
$ bzip2 -k noarch/repodata.json
.

CondaHTTPError: HTTP None None for url <http://pypi.python.com/osx-64/repodata.json>
Elapsed: None

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(MaxRetryError("HTTPConnectionPool(host='pypi.python.com', port=80): Max retries exceeded with url: /osx-64/repodata.json (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x1119ee710>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))",),)
➜ ~ cd anaconda
2、然后我们这样解决修改源地址,主要在 “.condarc”这个文件里面。我们添加清华源:https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
➜  ~ cd anaconda
➜ anaconda sudo conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Password:
➜ anaconda sudo conda config --set show_channel_urls yes

➜ anaconda sudo conda create -n tensorflow
Fetching package metadata .....
Solving package specifications:
Package plan for installation in environment /Users/xiaobai/anaconda/envs/tensorflow:

Proceed ([y]/n)? y

#
# To activate this environment, use:
# > source activate tensorflow
#
# To deactivate this environment, use:
# > source deactivate tensorflow
#
➜ ~ cd anaconda

我们最好是直接去操作 “.condarc”的文件,将地址改为国内的地址。然后sudo conda config –set show_channel_urls yes。

3、然后进入我们创建的tensorflow的环境,来安装tensorflow。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
➜  anaconda source activate tensorflow
(tensorflow) ➜ anaconda sudo pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py3-none-any.whl
The directory '/Users/xiaobai/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/xiaobai/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 tensorflow==1.1.0 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py3-none-any.whl
Downloading https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py3-none-any.whl (30.9MB)
100% |████████████████████████████████| 30.9MB 21kB/s
Collecting six>=1.10.0 (from tensorflow==1.1.0)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting wheel>=0.26 (from tensorflow==1.1.0)
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 156kB/s
Collecting werkzeug>=0.11.10 (from tensorflow==1.1.0)
Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
100% |████████████████████████████████| 317kB 140kB/s
Collecting numpy>=1.11.0 (from tensorflow==1.1.0)
Downloading numpy-1.12.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.4MB)
100% |████████████████████████████████| 4.4MB 49kB/s
Collecting protobuf>=3.2.0 (from tensorflow==1.1.0)
Downloading protobuf-3.3.0.tar.gz (271kB)
100% |████████████████████████████████| 276kB 97kB/s
Collecting setuptools (from protobuf>=3.2.0->tensorflow==1.1.0)
Downloading setuptools-35.0.2-py2.py3-none-any.whl (390kB)
100% |████████████████████████████████| 399kB 121kB/s
Collecting appdirs>=1.4.0 (from setuptools->protobuf>=3.2.0->tensorflow==1.1.0)
Downloading appdirs-1.4.3-py2.py3-none-any.whl
Collecting packaging>=16.8 (from setuptools->protobuf>=3.2.0->tensorflow==1.1.0)
Downloading packaging-16.8-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools->protobuf>=3.2.0->tensorflow==1.1.0)
Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 56kB/s
Installing collected packages: six, wheel, werkzeug, numpy, appdirs, pyparsing, packaging, setuptools, protobuf, tensorflow
Running setup.py install for protobuf ... done
Successfully installed appdirs-1.4.3 numpy-1.12.1 packaging-16.8 protobuf-3.3.0 pyparsing-2.2.0 setuptools-35.0.2 six-1.10.0 tensorflow-1.1.0 werkzeug-0.12.2 wheel-0.29.0
➜ anaconda
4、测试成功

不过一些加快cpu指令不能执行,因为我们使用的pip的安装方式,为了填这个坑,不得不卸载,采用源安装。。。。坑啊!白激动了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
➜  anaconda python
Python 3.6.0 |Anaconda custom (x86_64)| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-05-20 23:19:36.415562: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-20 23:19:36.415585: 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-05-20 23:19:36.415591: 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-05-20 23:19:36.415596: 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-05-20 23:19:36.415600: 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.
>>> print(sess.run(hello))
b'Hello, TensorFlow!'

二、源码安装tensorflow

1、现在我们要卸载tensorflow
1
2
3
4
5
6
7
8
9
10
➜  anaconda sudo pip uninstall tensorflow
/Users/xiaobai/anaconda/lib/python3.6/site-packages/tensorflow/tools/tfprof/__pycache__/tfprof_output_pb2.cpython-36.pyc
....
/Users/xiaobai/anaconda/lib/python3.6/site-packages/tensorflow/tools/tfprof/tfprof_log_pb2.py
/Users/xiaobai/anaconda/lib/python3.6/site-packages/tensorflow/tools/tfprof/tfprof_options_pb2.py
/Users/xiaobai/anaconda/lib/python3.6/site-packages/tensorflow/tools/tfprof/tfprof_output_pb2.py
Proceed (y/n)? y
Successfully uninstalled tensorflow-1.1.0
The directory '/Users/xiaobai/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.
➜ anaconda
2、安装Java SE Development Kit
3、切换到根目录usr,安装Homebrew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
➜  /usr bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Homebrew
/usr/local/Frameworks

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew /usr/local/Frameworks
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown xiaobai /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown xiaobai /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 4267, done.
remote: Compressing objects: 100% (2809/2809), done.
remote: Total 4267 (delta 2206), reused 2751 (delta 1310), pack-reused 0
Receiving objects: 100% (4267/4267), 2.44 MiB | 54.00 KiB/s, done.
Resolving deltas: 100% (2206/2206), done.
From https://github.com/Homebrew/brew
* [new branch] master -> origin/master
* [new tag] 0.1 -> 0.1
* [new tag] 0.2 -> 0.2
* [new tag] 0.3 -> 0.3
* [new tag] 0.4 -> 0.4
* [new tag] 0.5 -> 0.5
* [new tag] 0.6 -> 0.6
* [new tag] 0.7 -> 0.7
* [new tag] 0.7.1 -> 0.7.1
* [new tag] 0.8 -> 0.8
* [new tag] 0.8.1 -> 0.8.1
* [new tag] 0.9 -> 0.9
* [new tag] 0.9.1 -> 0.9.1
* [new tag] 0.9.2 -> 0.9.2
* [new tag] 0.9.3 -> 0.9.3
* [new tag] 0.9.4 -> 0.9.4
* [new tag] 0.9.5 -> 0.9.5
* [new tag] 0.9.8 -> 0.9.8
* [new tag] 0.9.9 -> 0.9.9
* [new tag] 1.0.0 -> 1.0.0
* [new tag] 1.0.1 -> 1.0.1
* [new tag] 1.0.2 -> 1.0.2
* [new tag] 1.0.3 -> 1.0.3
* [new tag] 1.0.4 -> 1.0.4
* [new tag] 1.0.5 -> 1.0.5
* [new tag] 1.0.6 -> 1.0.6
* [new tag] 1.0.7 -> 1.0.7
* [new tag] 1.0.8 -> 1.0.8
* [new tag] 1.0.9 -> 1.0.9
* [new tag] 1.1.0 -> 1.1.0
* [new tag] 1.1.1 -> 1.1.1
* [new tag] 1.1.2 -> 1.1.2
* [new tag] 1.1.3 -> 1.1.3
* [new tag] 1.1.4 -> 1.1.4
* [new tag] 1.1.5 -> 1.1.5
HEAD is now at 7000f50 Merge pull request #2646 from sjackman/replace_text_in_files
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
<!-- 这个位置会等待非常长非常长的时间,请耐心等待,然后我们看到这个: -->
remote: Counting objects: 4419, done.
remote: Compressing objects: 100% (4225/4225), done.
remote: Total 4419 (delta 37), reused 473 (delta 14), pack-reused 0
Receiving objects: 100% (4419/4419), 3.52 MiB | 5.00 KiB/s, done.
Resolving deltas: 100% (37/37), done.
Tapped 4224 formulae (4,462 files, 11.0MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/xiaobai/Library/Caches/Homebrew
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
Error: Could not link:
/usr/local/etc/bash_completion.d/brew

Please delete these paths and run `brew update`.
Error: Could not link:
/usr/local/share/zsh/site-functions/_brew

Please delete these paths and run `brew update`.
Error: Could not link:
/usr/local/share/man/man1/brew.1

Please delete these paths and run `brew update`.
Error: Could not link:
/usr/local/share/doc/homebrew

Please delete these paths and run `brew update`.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
http://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation:
http://docs.brew.sh
➜ /usr
4、升级brew,完成安装

按照提示,我们删除对应的文件和文件夹,然后运行:

1
2
3
➜  /usr brew update
Already up-to-date.
➜ /usr

5、然后我们就可以安装bazel了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
➜  /usr brew install bazel
==> Downloading https://homebrew.bintray.com/bottles/bazel-0.4.5.sierra.bottle.t
######################################################################## 100.0%
==> Pouring bazel-0.4.5.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d

zsh completions have been installed to:
/usr/local/share/zsh/site-functions
==> Summary
🍺 /usr/local/Cellar/bazel/0.4.5: 11 files, 137.4MB
➜ /usr bazel version
Extracting Bazel installation...
Build label: 0.4.5-homebrew
Build target: bazel-out/local-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Mar 16 13:39:33 2017 (1489671573)
Build timestamp: 1489671573
Build timestamp as int: 1489671573
➜ /usr
6、安装python依赖包,通常已经安装了,如果没有请定位到anaconda下安装
1
2
3
➜  ~ cd anaconda
➜ anaconda sudo pip install six numpy wheel
➜ ~ cd anaconda
7、下面我们克隆tensorflow库到本地
1
2
3
4
5
6
7
8
➜  ~ cd anaconda
➜ anaconda git clone https://github.com/tensorflow/tensorflow
Cloning into 'tensorflow'...
remote: Counting objects: 187859, done.
remote: Total 187859 (delta 0), reused 0 (delta 0), pack-reused 187859
Receiving objects: 100% (187859/187859), 103.48 MiB | 347.00 KiB/s, done.
Resolving deltas: 100% (143705/143705), done.
➜ ~ cd anaconda
7、配置tensorflow

注意我对每一个项目配置的选择。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
➜  ~ cd anaconda
➜ anaconda cd tensorflow
➜ tensorflow git:(master) ./configure
Please specify the location of python. [Default is /Users/xiaobai/anaconda/bin/python]:
Found possible Python library paths:
/Users/xiaobai/anaconda/lib/python3.6/site-packages
Please input the desired Python library path to use. Default is [/Users/xiaobai/anaconda/lib/python3.6/site-packages]

Using python library path: /Users/xiaobai/anaconda/lib/python3.6/site-packages
Do you wish to build TensorFlow with MKL support? [y/N] n
No MKL support will be enabled for TensorFlow
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] y
Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N] y
Hadoop File System support will be enabled for TensorFlow
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] n
No XLA JIT support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N] n
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with OpenCL support? [y/N] n
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] n
No CUDA support will be enabled for TensorFlow
...........................
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.
Configuration finished
➜ tensorflow git:(master)

8、生成一个pip的安装包

如果你的网络环境不错,这会是个漫长的等待。

如果网络环境不好,请安装提示手动下载,移到指定目录,然后再次运行命令!因为中国网络环境很那个,你懂的!

你可能需要反复操作几次,切忌烦躁,耐心操作。

最后编译,将会消耗大量计算资源,并会有警告信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
➜  tensorflow git:(master) sudo bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
Password:
INFO: Downloading http://mirror.bazel.build/pypi.python.org/packages/b7/7f/44d3cfe5a12ba002b253f6985a4477edfa66da53\
787a2a838a40f6415263/Werkzeug-0.11.10.tar.gz: 764,355 bytes
...
tensorflow/core/kernels/hexagon/hexagon_control_wrapper.cc:35:12: warning: unused variable 'DBG_DUMP_INPUT_TENSOR_AS_FLOAT_DATA' [-Wunused-const-variable]
const bool DBG_DUMP_INPUT_TENSOR_AS_FLOAT_DATA = false;
^
In file included from tensorflow/core/kernels/hexagon/hexagon_control_wrapper.cc:16:
./tensorflow/core/kernels/hexagon/hexagon_control_wrapper.h:56:38: warning: private field 'execute_info_' is not used [-Wunused-private-field]
const RemoteFusedGraphExecuteInfo* execute_info_{};
^
9 warnings generated.
INFO: From Linking tensorflow/cc/libcc_ops_internal.pic.lo:
...

l-py3-opt/bin/external/grpc/libgrpc_unsecure.pic.a(census.pb.pic.o))
ld: warning: pointer not aligned at address 0x2C494A6 (_grpc_lb_v1_LoadBalanceRequest_fields + 6 from bazel-out/local-py3-opt/bin/external/grpc/libgrpc_unsecure.pic.a(load_balancer.pb.pic.o))
ld: warning: pointer not aligned at address 0x2C49506 (_grpc_lb_v1_ServerList_fields + 6 from bazel-out/local-py3-opt/bin/external/grpc/libgrpc_unsecure.pic.a(load_balancer.pb.pic.o))
ld: warning: pointer not aligned at address 0x2C49536 (_grpc_lb_v1_LoadBalanceResponse_fields + 6 from bazel-out/local-py3-opt/bin/external/grpc/libgrpc_unsecure.pic.a(load_balancer.pb.pic.o))
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 4804.411s, Critical Path: 1838.71s
➜ tensorflow git:(master)

9、创建whl安装包

上述命令会生成一个叫做build_pip_package的脚本,按照如下命令运行这个脚本,在/tmp/tensorflow_pkg文件夹中创建”.whl”的文件。也就说用上一步的脚本创建一个whl安装包

1
2
3
4
5
6
7
8
9
10
11
12
➜  tensorflow git:(master) sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Password:
2017年 5月21日 星期日 16时41分34秒 CST : === Using tmpdir: /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/tmp.XXXXXXXXXX.gPUDRm6k
~/anaconda/tensorflow/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles ~/anaconda/tensorflow
~/anaconda/tensorflow
/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/tmp.XXXXXXXXXX.gPUDRm6k ~/anaconda/tensorflow
2017年 5月21日 星期日 16时41分38秒 CST : === Building wheel
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
~/anaconda/tensorflow
2017年 5月21日 星期日 16时41分59秒 CST : === Output wheel file is in: /tmp/tensorflow_pkg
➜ tensorflow git:(master)
10、用pip安装whl安装包

退出tensorflow环境,进入anaconda环境。注意你的whl文件名,我的文件名是:tensorflow-1.1.0-cp36-cp36m-macosx_10_7_x86_64.whl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
➜  anaconda sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0-cp36-cp36m-macosx_10_7_x86_64.whl
The directory '/Users/xiaobai/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/xiaobai/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.
Processing /tmp/tensorflow_pkg/tensorflow-1.1.0-cp36-cp36m-macosx_10_7_x86_64.whl
Requirement already satisfied: six>=1.10.0 in ./lib/python3.6/site-packages (from tensorflow==1.1.0)
Requirement already satisfied: wheel>=0.26 in ./lib/python3.6/site-packages (from tensorflow==1.1.0)
Requirement already satisfied: werkzeug>=0.11.10 in ./lib/python3.6/site-packages (from tensorflow==1.1.0)
Collecting html5lib==0.9999999 (from tensorflow==1.1.0)
Downloading html5lib-0.9999999.tar.gz (889kB)
100% |████████████████████████████████| 890kB 786kB/s
Requirement already satisfied: numpy>=1.11.0 in ./lib/python3.6/site-packages (from tensorflow==1.1.0)
Requirement already satisfied: protobuf>=3.2.0 in ./lib/python3.6/site-packages (from tensorflow==1.1.0)
Collecting markdown==2.2.0 (from tensorflow==1.1.0)
Downloading Markdown-2.2.0.tar.gz (236kB)
100% |████████████████████████████████| 245kB 2.7MB/s
Collecting bleach==1.5.0 (from tensorflow==1.1.0)
Downloading bleach-1.5.0-py2.py3-none-any.whl
Requirement already satisfied: setuptools in ./lib/python3.6/site-packages (from protobuf>=3.2.0->tensorflow==1.1.0)
Requirement already satisfied: appdirs>=1.4.0 in ./lib/python3.6/site-packages (from setuptools->protobuf>=3.2.0->tensorflow==1.1.0)
Requirement already satisfied: packaging>=16.8 in ./lib/python3.6/site-packages (from setuptools->protobuf>=3.2.0->tensorflow==1.1.0)
Requirement already satisfied: pyparsing in ./lib/python3.6/site-packages (from packaging>=16.8->setuptools->protobuf>=3.2.0->tensorflow==1.1.0)
Installing collected packages: html5lib, markdown, bleach, tensorflow
Running setup.py install for html5lib ... done
Running setup.py install for markdown ... done
Successfully installed bleach-1.5.0 html5lib-0.9999999 markdown-2.2.0 tensorflow-1.1.0

11、安装成功,指令集的错误没有了,噢耶!
1
2
3
4
5
6
7
8
9
10
➜  anaconda python
Python 3.6.0 |Anaconda custom (x86_64)| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello).decode('utf-8'))
Hello, TensorFlow!
>>>

三、评述

这样我们就安装好了tensorflow。坑不少,但是安装官方help基本没有问题。
我们来总结一下tensorflowr1.2.0rc2的编译安装:

1、安装Java SE Development Kit
2、切换到根目录usr,安装Homebrew

➜ /usr bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
➜ /usr brew update

3、然后安装bazel。

➜ /usr brew install bazel


1、指定目录

➜ ~ cd anaconda

2、克隆下来

➜ anaconda git clone https://github.com/tensorflow/tensorflow

3、指定版本

➜ ~ cd anaconda/tensorflow
➜ tensorflow git checkout r1.2.0rc2

4、配置tensorflow

➜ tensorflow git:(ce1d6ec49) ./configure

4、生成一个pip的安装包,mac和lunix系统,默认会编译指令集,win的好像要手动设置

➜ tensorflow git:(ce1d6ec49) sudo bazel build –config=opt //tensorflow/tools/pip_package:build_pip_package

5、创建whl安装包

➜ tensorflow git:(ce1d6ec49) bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

6、用pip安装whl安装包

➜ anaconda sudo pip install /tmp/tensorflow_pkg/tensorflow-1.2.0rc2-cp36-cp36m-macosx_10_7_x86_64.whl


注意:win的好像要手动设置

bazel build -c opt –copt=-mavx –copt=-msse4.1 –copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package

在GitHub上,有人编译好了,地址是 https://github.com/lakshayg/tensorflow-build


版权声明
引线小白创作并维护的柠檬CC博客采用署名-非商业-禁止演绎4.0国际许可证。
本文首发于柠檬CC [ http://www.limoncc.com ] , 版权所有、侵权必究。
本文永久链接http://www.limoncc.com/工程实践/2017-05-04-Mac下Tensorflow的安装/

予汝玫瑰,渡人沃土。