6

我正在尝试在 El 10.11.1 上安装 TensorFlow,但在创建和安装我完全不理解的 pip 包时遇到了问题。

我按照说明成功安装了 Bazel、SWIG 和 NumPy (至少此时它们似乎都可以工作)。

创建 pip 包/安装运行命令时出现以下错误:

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

/Users/christophermichael/tensorflow/tensorflow/tensorflow/python/BUILD:730:1:规则'//tensorflow/python:_pywrap_tensorflow.so'的C++编译失败:osx_gcc_wrapper.sh失败:错误执行命令

运行--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
4

3 回答 3

4

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

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

  • 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
于 2015-12-03T18:03:47.687 回答
3

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

这是使用 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.08.x 的 numpy 版本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 和 numpy 有问题。手动安装后一切正常。

我希望这有帮助!

于 2016-01-12T14:32:46.890 回答
1

为什么要从源安装?

创建一个 virtualenv 并将其安装在那里,我有相同的操作系统版本,并且通过这种方法可以很好地工作:

https://stackoverflow.com/a/33691154/1973820

于 2015-11-16T13:54:11.447 回答