这里要为仅支持 CPU 的 TensorFlow 构建一个 pip 软件包,需要调用以下命令:
$ bazel build –cxxopt=”-D_GLIBCXX_USE_CXX11_ABI=0″ –config=opt –verbose_failures //tensorflow/tools/pip_package:build_pip_package
大概编译15分钟后,输出错误信息如下:
ERROR: /private/var/tmp/_bazel_mazhiyong/54650f23f4cec88510e7895c92a68913/external/protobuf_archive/BUILD:659:1: C++ compilation of rule ‘@protobuf_archive//:python/google/protobuf/pyext/_message.so’ failed (Exit 1)
external/protobuf_archive/python/google/protobuf/pyext/message.cc:547:11: error: assigning to ‘char *’ from incompatible type ‘const char *’
if (PyString_AsStringAndSize(key, &key_str_data, &key_str_size) != 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:82:22: note: expanded from macro ‘PyString_AsStringAndSize’
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:998:7: error: assigning to ‘char *’ from incompatible type ‘const char *’
if (PyString_AsStringAndSize(name, &field_name, &size) < 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:82:22: note: expanded from macro ‘PyString_AsStringAndSize’
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:1035:9: error: assigning to ‘char *’ from incompatible type ‘const char *’
if (PyString_AsStringAndSize(value, &enum_label, &size) < 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:82:22: note: expanded from macro ‘PyString_AsStringAndSize’
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:1532:16: error: assigning to ‘char *’ from incompatible type ‘const char *’
field_name = PyUnicode_AsUTF8AndSize(arg, &size);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:2048:7: warning: ‘PyObject_AsReadBuffer’ is deprecated [-Wdeprecated-declarations]
if (PyObject_AsReadBuffer(arg, &data, &data_length) < 0) {
^
bazel-out/darwin-opt/genfiles/external/local_config_python/python_include/abstract.h:492:39: note: ‘PyObject_AsReadBuffer’ has been explicitly marked deprecated here
Py_DEPRECATED(3.0);
^
bazel-out/darwin-opt/genfiles/external/local_config_python/python_include/pyport.h:493:54: note: expanded from macro ‘Py_DEPRECATED’
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
external/protobuf_archive/python/google/protobuf/pyext/message.cc:2119:7: error: assigning to ‘char *’ from incompatible type ‘const char *’
if (PyString_AsStringAndSize(arg, &name_data, &name_size) < 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/protobuf_archive/python/google/protobuf/pyext/message.cc:82:22: note: expanded from macro ‘PyString_AsStringAndSize’
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 5 errors generated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use –verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 771.278s, Critical Path: 26.15s
INFO: 2156 processes: 2156 local.
FAILED: Build did NOT complete successfully
这个错误我估计是编译器与代码兼容的问题,查找了半天暂时没找到解决办法,所以就暂时搁置了TensorFlow主分支代码在Python3.7环境下的代码编译,过一段时间再试试。