天天看點

Mac 編譯安裝Tensorflow

安裝依賴

安裝 bazel
$ brew install bazel

安裝 python 依賴
$ pip3 install numpy scipy matplotlib ipython jupyter pandas sympy nose

安裝 keras
最新版 tensorflow 1.12 需要依賴這個
python 3.6.6 編譯,提示缺少 beras
ModuleNotFoundError: No module named 'keras_applications'

$ pip3 install keras
           

icu4c 未測試是否需要

$ brew install icu4c
           

安裝完成後的 pip list

$ pip list
Package              Version
-------------------- ---------
absl-py              0.6.1
appnope              0.1.0
astor                0.7.1
backcall             0.1.0
bleach               3.0.0
cycler               0.10.0
decorator            4.3.0
defusedxml           0.5.0
entrypoints          0.2.3
gast                 0.2.0
grpcio               1.16.0
h5py                 2.8.0
ipykernel            5.0.0
ipython              7.0.1
ipython-genutils     0.2.0
ipywidgets           7.4.2
jedi                 0.13.1
Jinja2               2.10
jsonschema           2.6.0
jupyter              1.0.0
jupyter-client       5.2.3
jupyter-console      6.0.0
jupyter-core         4.4.0
Keras                2.2.4
Keras-Applications   1.0.6
Keras-Preprocessing  1.0.5
kiwisolver           1.0.1
Markdown             3.0.1
MarkupSafe           1.0
matplotlib           3.0.0
mistune              0.8.3
mock                 2.0.0
mpmath               1.0.0
msgpack-python       0.5.6
nbconvert            5.4.0
nbformat             4.4.0
nose                 1.3.7
notebook             5.7.0
numpy                1.15.2
pandas               0.23.4
pandocfilters        1.4.2
parso                0.3.1
pbr                  5.1.0
pexpect              4.6.0
pickleshare          0.7.5
pip                  18.1
prometheus-client    0.4.0
prompt-toolkit       2.0.5
protobuf             3.6.1
ptyprocess           0.6.0
Pygments             2.2.0
pyleus               0.3.0
pyltp                0.2.1
pyparsing            2.2.2
pypi                 2.1
python-dateutil      2.7.3
pytz                 2018.5
PyYAML               3.13
pyzmq                17.1.2
qtconsole            4.4.1
scipy                1.1.0
Send2Trash           1.5.0
setuptools           40.5.0
simplegeneric        0.8.1
six                  1.11.0
sympy                1.3
tensorboard          1.12.0
tensorflow           1.12.0rc0
tensorflow-estimator 1.10.12
termcolor            1.1.0
terminado            0.8.1
testpath             0.4.2
tornado              5.1.1
traitlets            4.3.2
virtualenv           16.0.0
wcwidth              0.1.7
webencodings         0.5.1
Werkzeug             0.14.1
wheel                0.32.2
widgetsnbextension   3.4.2
           

編譯過程

  1. 克隆
$ git clone https://github.com/tensorflow/tensorflow
           
  1. 進入目錄
$ cd tensorflow
           
  1. configure
$ ./configure
WARNING: Running Bazel server needs to be killed, because the startup options are different.
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.17.2-homebrew installed.
Please specify the location of python. [Default is /usr/bin/python]: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6


Found possible Python library paths:
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Please input the desired Python library path to use.  Default is [/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages]
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm 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.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI 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 -Wno-sign-compare]:


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=noaws       	# Disable AWS S3 filesystem support.
	--config=nogcp       	# Disable GCP support.
	--config=nohdfs      	# Disable HDFS support.
	--config=noignite    	# Disable Apacha Ignite support.
	--config=nokafka     	# Disable Apache Kafka support.
Configuration finished

           
  1. build
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
           

天知道等這幾句話多不容易

INFO: Analysed target //tensorflow/tools/pip_package:build_pip_package (0 packages loaded).
INFO: Found 1 target...
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
  bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 5.635s, Critical Path: 2.60s
INFO: 2 processes: 2 local.
INFO: Build completed successfully, 3 total actions
           

編譯好後檔案目錄的結構

# munineyi @ MuNineyideMacBook-Pro in ~/Documents/GitHub/tensorflow on git:master o [10:08:26]
$ ls
ACKNOWLEDGMENTS    ISSUES.md          arm_compiler.BUILD configure.py
ADOPTERS.md        ISSUE_TEMPLATE.md  bazel-bin          models.BUILD
AUTHORS            LICENSE            bazel-genfiles     tensorflow
BUILD              README.md          bazel-out          third_party
CODEOWNERS         RELEASE.md         bazel-tensorflow   tools
CODE_OF_CONDUCT.md SECURITY.md        bazel-testlogs
CONTRIBUTING.md    WORKSPACE          configure
           
  1. 生成 pip 安裝包
更新 setup.py 
$ pip3 install setuptools --upgrade
安裝 wheel
$ pip3 install wheel
           
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/Python/tensorflow_pkg
2018年10月30日 星期二 10時06分27秒 CST : === Preparing sources in dir: /var/folders/yh/pmhsr91x6pzg0cgtvdqzbf540000gn/T/tmp.XXXXXXXXXX.syM2LvR1
~/Documents/GitHub/tensorflow ~/Documents/GitHub/tensorflow
~/Documents/GitHub/tensorflow
2018年10月30日 星期二 10時06分43秒 CST : === Building wheel
warning: no files found matching '*.pyd' under directory '*'
warning: no files found matching '*.pd' under directory '*'
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
warning: no files found matching '*.h' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*' under directory 'tensorflow/include/Eigen'
warning: no files found matching '*.h' under directory 'tensorflow/include/google'
warning: no files found matching '*' under directory 'tensorflow/include/third_party'
warning: no files found matching '*' under directory 'tensorflow/include/unsupported'
2018年10月30日 星期二 10時07分05秒 CST : === Output wheel file is in: /Users/munineyi/Python/tensorflow_pkg
           
  1. 安裝
$ pip install ~/Python/tensorflow_pkg/tensorflow-1.12.0rc0-cp36-cp36m-macosx_10_9_x86_64.whl
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing /Users/munineyi/Python/tensorflow_pkg/tensorflow-1.12.0rc0-cp36-cp36m-macosx_10_9_x86_64.whl
Collecting tensorflow-estimator>=1.10.0 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e7/5a/bace04b34b4a3214ed105899a27f3e94f0468b64bce46125ff42f495b1fc/tensorflow_estimator-1.10.12-py2.py3-none-any.whl (225kB)
    100% |████████████████████████████████| 235kB 10.0MB/s
Requirement already satisfied: keras-applications>=1.0.6 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow==1.12.0rc0) (1.0.6)
Collecting astor>=0.6.0 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Collecting absl-py>=0.1.6 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0c/63/f505d2d4c21db849cf80bad517f0065a30be6b006b0a5637f1b95584a305/absl-py-0.6.1.tar.gz (94kB)
    100% |████████████████████████████████| 102kB 13.8MB/s
Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow==1.12.0rc0) (1.11.0)
Requirement already satisfied: keras-preprocessing>=1.0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow==1.12.0rc0) (1.0.5)
Collecting termcolor>=1.1.0 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Requirement already satisfied: wheel>=0.26 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow==1.12.0rc0) (0.32.2)
Collecting protobuf>=3.6.1 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c7/27/133f225035b9539f2dcfebcdf9a69ff0152f56e0120160ec5c972ea7deb9/protobuf-3.6.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 (1.2MB)
    100% |████████████████████████████████| 1.2MB 5.0MB/s
Collecting gast>=0.2.0 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5c/78/ff794fcae2ce8aa6323e789d1f8b3b7765f601e7702726f430e814822b96/gast-0.2.0.tar.gz
Requirement already satisfied: numpy>=1.13.3 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow==1.12.0rc0) (1.15.2)
Collecting tensorboard<1.13.0,>=1.12.0 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e0/d0/65fe48383146199f16dbd5999ef226b87bce63ad5cd73c840cf722637969/tensorboard-1.12.0-py3-none-any.whl (3.0MB)
    100% |████████████████████████████████| 3.1MB 6.6MB/s
Collecting grpcio>=1.8.6 (from tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/66/19/445d9eb2a066da42d0be6b8c644500a92e7964744d5b3910c7ad5e2755c1/grpcio-1.16.0-cp36-cp36m-macosx_10_7_intel.whl (2.0MB)
    100% |████████████████████████████████| 2.0MB 9.1MB/s
Collecting mock>=2.0.0 (from tensorflow-estimator>=1.10.0->tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e6/35/f187bdf23be87092bd0f1200d43d23076cee4d0dec109f195173fd3ebc79/mock-2.0.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 9.4MB/s
Requirement already satisfied: h5py in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from keras-applications>=1.0.6->tensorflow==1.12.0rc0) (2.8.0)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow==1.12.0rc0) (40.5.0)
Collecting werkzeug>=0.11.10 (from tensorboard<1.13.0,>=1.12.0->tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
    100% |████████████████████████████████| 327kB 9.2MB/s
Collecting markdown>=2.6.8 (from tensorboard<1.13.0,>=1.12.0->tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7a/6b/5600647404ba15545ec37d2f7f58844d690baf2f81f3a60b862e48f29287/Markdown-3.0.1-py2.py3-none-any.whl (89kB)
    100% |████████████████████████████████| 92kB 9.4MB/s
Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow-estimator>=1.10.0->tensorflow==1.12.0rc0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/0c/304d968fe010ba7c2ecc1d57e28741ddd3a305439dcf1cdb3b6f896a3c00/pbr-5.1.0-py2.py3-none-any.whl (106kB)
    100% |████████████████████████████████| 112kB 7.7MB/s
Building wheels for collected packages: absl-py, termcolor, gast
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: /Users/munineyi/Library/Caches/pip/wheels/26/21/57/d60e9344680ff0e98cf6c4fd9d440c44939fa5fe127deb9f4a
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: /Users/munineyi/Library/Caches/pip/wheels/2f/92/65/6ea67d77a7758e30316513984c98397217b478edb328d1c1e2
  Running setup.py bdist_wheel for gast ... done
  Stored in directory: /Users/munineyi/Library/Caches/pip/wheels/5f/b1/80/5779a170ca416a94795e231d0ed198aeca0062498b3562afa8
Successfully built absl-py termcolor gast
Installing collected packages: absl-py, pbr, mock, tensorflow-estimator, astor, termcolor, protobuf, gast, werkzeug, markdown, grpcio, tensorboard, tensorflow
Successfully installed absl-py-0.6.1 astor-0.7.1 gast-0.2.0 grpcio-1.16.0 markdown-3.0.1 mock-2.0.0 pbr-5.1.0 protobuf-3.6.1 tensorboard-1.12.0 tensorflow-1.12.0rc0 tensorflow-estimator-1.10.12 termcolor-1.1.0 werkzeug-0.14.1

           

多災多難的編譯過程

繼續閱讀