No such attribute 'licenses' in 'cc_shared_library' rule

Hello!

I’m working to build Tensorflow from source using the documentation found on the Tensorflow site, and seem to be running into a problem that I don’t quite understand how to resolve. Has anyone ever run into this?

ERROR: /app/tensorflow/tensorflow/python/BUILD:465:27: //tensorflow/python:_pywrap_tfcompile.so: no such attribute 'licenses' in 'cc_shared_library' rule
ERROR: /app/tensorflow/tensorflow/python/BUILD:515:27: //tensorflow/python:_pywrap_py_exception_registry.so: no such attribute 'licenses' in 'cc_shared_library' rule
ERROR: /app/tensorflow/tensorflow/python/BUILD:1169:27: //tensorflow/python:_pywrap_tfe.so: no such attribute 'licenses' in 'cc_shared_library' rule
ERROR: /app/tensorflow/tensorflow/BUILD:1665:14: Target '//tensorflow/python:modules_with_exports' contains an error and its package is in error and referenced by '//tensorflow:tf_python_api_gen_v2.extract-tensorflow'
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis failed

Does anyone have any thoughts about what I can do here to resolve this?

Thanks!!!

Ah, I was running Bazel 7.0.2. I downgraded to 6.5 and it moved beyond this error. (To another one of course)

It seems you’re encountering an issue related to the licenses attribute in the Bazel build configuration files (BUILD files) while trying to build TensorFlow from source. This error is typically a result of a mismatch between the version of Bazel you’re using and the expectations set forth in the TensorFlow source code. TensorFlow’s BUILD files are written for specific versions of Bazel, and newer or older versions of Bazel may have different requirements or not support certain attributes.

Here’s a step-by-step approach to troubleshoot and potentially resolve this issue:

1. Check Bazel Version

Ensure that you are using the correct version of Bazel that is compatible with the TensorFlow source code you are trying to build. TensorFlow’s official documentation usually specifies the compatible Bazel version. If you’re working with the latest TensorFlow source from the repository, check the .bazelversion file at the root of the repository or refer to the TensorFlow documentation for the required Bazel version.

2. Update or Downgrade Bazel

If your Bazel version is not compatible, consider updating or downgrading it. You can download specific versions of Bazel from the Bazel GitHub releases page.

3. Review BUILD Files

If your Bazel version is correct and you still encounter the error, review the BUILD files mentioned in the error messages. It’s possible that the TensorFlow source code you’re working with has some inconsistencies. If you’ve made changes to the BUILD files, ensure that these changes are compatible with Bazel’s expectations.

4. Sync to a Stable Branch or Tag

If you’re working with the master branch or an unstable branch of TensorFlow, consider switching to a stable release branch or tag. The master branch can contain experimental changes that might not be fully tested with all build configurations.

5. Clean and Rebuild

Sometimes, residual files from previous builds can cause issues. Use Bazel’s clean command (bazel clean --expunge) to remove all artifacts from the build and output directories, then try building again.

6. Consult TensorFlow Community

If the problem persists, consider reaching out to the TensorFlow community. You can post your issue on the TensorFlow GitHub issues page or the TensorFlow discussion forum. Provide detailed information about the issue, including the steps you’ve taken, Bazel version, TensorFlow version or commit hash, and any relevant error messages.

7. Patch BUILD Files (Advanced)

As a last resort, and if you’re comfortable with Bazel and TensorFlow’s build system, you can manually edit the BUILD files to remove or comment out the licenses attribute. This approach is not recommended unless you are familiar with TensorFlow’s build system and are prepared to maintain your own fork of the code.

Remember, building TensorFlow from source can be complex and requires careful alignment of tool versions and dependencies. Always refer to the official TensorFlow documentation for guidance on building from source.