Tensorflow 安装 OSX

Tensor flow install OSX

我正在尝试在 El 10.11.1 上安装 TensorFlow,但我在创建和安装 pip 包时遇到了问题,我根本不明白。

我成功安装了 Bazel、SWIG 和 NumPy per instructions(至少它们目前似乎都可以工作)。

创建 pip package/install 当我 运行 命令时出现以下错误:

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

/Users/christophermichael/tensorflow/tensorflow/tensorflow/python/BUILD:730:1: C++ compilation of rule '//tensorflow/python:_pywrap_tensorflow.so' failed: osx_gcc_wrapper.sh failed: error executing command

运行 --verbose_failures, 我得到:

/Users/christophermichael/tensorflow/tensorflow/tensorflow/python/BUILD:730:1: C++ compilation of rule '//tensorflow/python:_pywrap_tensorflow.so' failed: osx_gcc_wrapper.sh failed: error executing command 
(cd /private/var/tmp/_bazel_christophermichael/b14fc0915a4b8dd526e88d50650b0640/tensorflow && \
  exec env - \
    INTERCEPT_LOCALLY_EXECUTABLE=1 \
    PATH=/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/christophermichael/bin \
    TMPDIR=/var/folders/tv/rgqv4fp54mn952pn_v0tjwt80000gn/T/ \
  tools/cpp/osx_gcc_wrapper.sh '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -iquote . -iquote bazel-out/local_darwin-opt/genfiles -isystem google/protobuf/src -isystem bazel-out/local_darwin-opt/genfiles/google/protobuf/src -isystem tools/cpp/gcc3 -isystem external/jpeg_archive/jpeg-9a -isystem bazel-out/local_darwin-opt/genfiles/external/jpeg_archive/jpeg-9a -isystem external/png_archive/libpng-1.2.53 -isystem bazel-out/local_darwin-opt/genfiles/external/png_archive/libpng-1.2.53 -isystem external/re2 -isystem bazel-out/local_darwin-opt/genfiles/external/re2 -isystem third_party/gpus/cuda -isystem bazel-out/local_darwin-opt/genfiles/third_party/gpus/cuda -isystem third_party/gpus/cuda/include -isystem bazel-out/local_darwin-opt/genfiles/third_party/gpus/cuda/include -isystem third_party/eigen3 -isystem bazel-out/local_darwin-opt/genfiles/third_party/eigen3 -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -Wno-self-assign -Wno-write-strings -I/usr/include/python2.7 -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' '-frandom-seed=bazel-out/local_darwin-opt/bin/tensorflow/python/_objs/_pywrap_tensorflow.so/tensorflow/python/pywrap_tensorflow.pic.o' -MD -MF bazel-out/local_darwin-opt/bin/tensorflow/python/_objs/_pywrap_tensorflow.so/tensorflow/python/pywrap_tensorflow.pic.d -fPIC -c bazel-out/local_darwin-opt/bin/tensorflow/python/pywrap_tensorflow.cc -o bazel-out/local_darwin-opt/bin/tensorflow/python/_objs/_pywrap_tensorflow.so/tensorflow/python/pywrap_tensorflow.pic.o): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1: osx_gcc_wrapper.sh failed: error executing command 
  (cd /private/var/tmp/_bazel_christophermichael/b14fc0915a4b8dd526e88d50650b0640/tensorflow && \
  exec env - \
    INTERCEPT_LOCALLY_EXECUTABLE=1 \
    PATH=/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/christophermichael/bin \
    TMPDIR=/var/folders/tv/rgqv4fp54mn952pn_v0tjwt80000gn/T/ \
  tools/cpp/osx_gcc_wrapper.sh '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -iquote . -iquote bazel-out/local_darwin-opt/genfiles -isystem google/protobuf/src -isystem bazel-out/local_darwin-opt/genfiles/google/protobuf/src -isystem tools/cpp/gcc3 -isystem external/jpeg_archive/jpeg-9a -isystem bazel-out/local_darwin-opt/genfiles/external/jpeg_archive/jpeg-9a -isystem external/png_archive/libpng-1.2.53 -isystem bazel-out/local_darwin-opt/genfiles/external/png_archive/libpng-1.2.53 -isystem external/re2 -isystem bazel-out/local_darwin-opt/genfiles/external/re2 -isystem third_party/gpus/cuda -isystem bazel-out/local_darwin-opt/genfiles/third_party/gpus/cuda -isystem third_party/gpus/cuda/include -isystem bazel-out/local_darwin-opt/genfiles/third_party/gpus/cuda/include -isystem third_party/eigen3 -isystem bazel-out/local_darwin-opt/genfiles/third_party/eigen3 -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -Wno-self-assign -Wno-write-strings -I/usr/include/python2.7 -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' '-frandom-seed=bazel-out/local_darwin-opt/bin/tensorflow/python/_objs/_pywrap_tensorflow.so/tensorflow/python/pywrap_tensorflow.pic.o' -MD -MF bazel-out/local_darwin-opt/bin/tensorflow/python/_objs/_pywrap_tensorflow.so/tensorflow/python/pywrap_tensorflow.pic.d -fPIC -c bazel-out/local_darwin-opt/bin/tensorflow/python/pywrap_tensorflow.cc -o bazel-out/local_darwin-opt/bin/tensorflow/python/_objs/_pywrap_tensorflow.so/tensorflow/python/pywrap_tensorflow.pic.o): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 4.940s, Critical Path: 3.69s

为什么要从源安装?

创建一个 virtualenv 并将其安装在那里,我有相同的 OS 版本并且通过这种方法它工作得非常好:

是的,正如哈米德上面所说,最好直接安装二进制文件。

但是,如果您确实需要从源代码构建,那么这些步骤应该有效:

  • brew install python
  • virtualenv ~/tf
  • source ~/tf/bin/activate
  • 为 Mac
  • 安装 bazel
  • 为 Mac
  • 安装 PCRE(不是 PCRE2)
  • 为 Mac
  • 安装 SWIG
  • git clone --recurse-submodules https://github.com/tensorflow/tensorflow
  • cd tensorflow
  • ./configure
  • bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
  • bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
  • pip install /tmp/tensorflow_pkg/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
  • bazel build -c opt //tensorflow/cc:tutorials_example_trainer

另一种选择是安装anaconda 并使用其环境管理。使用 anaconda 或 virtualenv 的环境的优点是您可以为不同的用例分离源和依赖项。这意味着,如果您需要为其他内容更改 python 库,它不会影响您的 tensorflow environmnet。

下面是如何使用anaconda安装tensorflow。

  1. 安装 anaconda http://docs.continuum.io/anaconda/install
  2. 创建一个新的 conda 工作区
  3. 下载tensorflow需要的具体protobuf版本:https://pypi.python.org/pypi/protobuf/3.0.0a3
  4. 通过 sudo easy_install ~/Downloads/protobuf-3.0.0a3-py2.7.egg 安装它
  5. 安装大于 1 的 numpy 版本。08.x 通过 conda install numpy
  6. 下载tensorflow 0.6.0版本: https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py2-none-any.whl

  7. 通过 pip install ~/Downloads/tensorflow-0.6.0-py2-none-any.whl 安装

安装时 直接来自whl文件的tensorflow,它应该告诉你什么时候 依赖关系不存在。好像不能解决这些 独立冲突。我的设置有问题 protobuf 和 麻木的。手动安装后一切正常。

希望对您有所帮助!