Mac安装tensorflow

来源:互联网 发布:iphone游戏推荐 知乎 编辑:程序博客网 时间:2024/05/21 09:29

1.二进制安装

  # brew install python

  # pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl//当前版本只支持 CPU

2.源码安装

  # brew install python

  # brew install bazel

  # pip install -U swig six numpy wheel

  # brew install coreutils //For CUDA(可选)

  # git clone --recurse-submodules https://github.com/tensorflow/tensorflow

  # cd tensorflow

  # ./configure //配置

报错解决

Do you wish to build TensorFlow with MKL support? [y/N] yMKL support will be enabled for TensorFlowDo you wish to download MKL LIB from the web? [Y/n] yDarwin is unsupported yet# 这里MKL不支持Darwin(MAC),因此要选择NERROR: /Users/***/Documents/tensorflow/tensorflow/core/BUILD:1331:1: C++ compilation of rule '//tensorflow/core:lib_hash_crc32c_accelerate_internal' failed: cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG ... (remaining 32 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.clang: error: no such file or directory: 'y'clang: error: no such file or directory: 'y'# 这里是因为在configure的时候有些包不支持但是选择了y,因此记住一点所有的都选N参考

  # bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package //编译CPU版本

  # bazel build --config=opt  --config=cuda  //tensorflow/tools/pip_package:build_pip_package //编译GPU版本

  # bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg//构建出.whl安装文件

  # pip install /tmp/tensorflow_pkg/tensorflow-1.2.0-cp27-cp27m-macosx_10_12_x86_64.whl//安装

3.测试:(新打开一个终端执行)

# Python
>>> import tensorflow as tf
>>> hello
= tf.constant('Hello, TensorFlow!')
>>>
sess = tf.Session()
>>> print(sess.run(hello))

4.卸载tensorflow

  # pip uninstall tensorflow

安装参考

原创粉丝点击