problems compilling tensorflow from source with bazel

  bazel, python, tensorflow

I have:

  • ubuntu 18.04
  • virtualenv python3.7

I installed tensorflow as follows:

$ pip install tensorflow (v2.4.1)

but when trying to execute some example or something like that I got the error

Illegal instruction

for example with:

$ python -c 'import tensorflow as tf;'
Illegal instruction

then, looking for info, I find that the problems is my pc not support GPU, it have an older CPU, then I try install:

$ pip install tensorflow-cpu (v2.4.1)

but I get de same problem then, looking for more info I found post like this:
https://tech.amikelive.com/node-887/how-to-resolve-error-illegal-instruction-core-dumped-when-running-import-tensorflow-in-a-python-program/

and I was decided compile tensorflow v2.4.1 from source just for CPU support for my pc with that guide and :
https://www.tensorflow.org/install/source?hl=es-419

$ gcc --version | grep "gcc" | awk '{print $4}'
7.5.0
$ grep flags -m1 /proc/cpuinfo |...... }
-march=native -mssse3 -mcx16

I had installed bazel 4.0.0, but

ERROR: The project you're trying to build requires Bazel 3.1.0 (specified in /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelversion), but it wasn't found in /usr/bin.

then uninstall and install required version 3.1.0 but when run:

$bazel-3.1.0 build [--config=option] --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package

I get a bazel error:

INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=177
INFO: Reading rc options for 'build' from /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc:
  'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --define=tensorflow_enable_mlir_generated_gpu_kernels=0 --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --noincompatible_prohibit_aapt1 --enable_platform_specific_config --config=short_logs --config=v2
INFO: Reading rc options for 'build' from /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.tf_configure.bazelrc:
  'build' options: --action_env PYTHON_BIN_PATH=/home/barcelo/projects-kivy/kivy-py37_venv/bin/python --action_env PYTHON_LIB_PATH=/home/barcelo/projects-kivy/kivy-py37_venv/lib/python3.7/site-packages --python_path=/home/barcelo/projects-kivy/kivy-py37_venv/bin/python --config=xla --action_env TF_CONFIGURE_IOS=0
INFO: Found applicable config definition build:short_logs in file /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:xla in file /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc: --define=with_xla_support=true
INFO: Found applicable config definition build:linux in file /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels
INFO: Found applicable config definition build:dynamic_kernels in file /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
INFO: Repository io_bazel_rules_go instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18: in <toplevel>
ERROR: An error occurred during the fetch of repository 'io_bazel_rules_go':
   Traceback (most recent call last):
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git.bzl", line 177
        _clone_or_update(ctx)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
        git_repo(ctx, directory)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, in git_repo
        _update(ctx, git_repo)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 103, in _update
        fetch(ctx, git_repo)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 129, in fetch
        _git_maybe_shallow(ctx, <5 more arguments>)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 171, in _git_maybe_shallow
        _error(ctx.name, <2 more arguments>)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 181, in _error
        fail(<1 more arguments>)
error running 'git fetch origin refs/heads/*:refs/remotes/origin/* refs/tags/*:refs/tags/*' while working with @io_bazel_rules_go:
fatal: unable to access 'https://github.com/bazelbuild/rules_go.git/': gnutls_handshake() failed: Se recibiĆ³ un paquete TLS inesperado.
INFO: Repository com_google_protobuf instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule tf_http_archive defined at:
  /home/barcelo/installers/tensorflow/tf-cpu/tensorflow-2.4.1/third_party/repo.bzl:131:19: in <toplevel>
ERROR: no such package '@io_bazel_rules_go//go': Traceback (most recent call last):
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git.bzl", line 177
        _clone_or_update(ctx)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
        git_repo(ctx, directory)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, in git_repo
        _update(ctx, git_repo)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 103, in _update
        fetch(ctx, git_repo)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 129, in fetch
        _git_maybe_shallow(ctx, <5 more arguments>)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 171, in _git_maybe_shallow
        _error(ctx.name, <2 more arguments>)
    File "/home/barcelo/.cache/bazel/_bazel_barcelo/439edbbfbd2bf2529f6095e04c168de1/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 181, in _error
        fail(<1 more arguments>)
error running 'git fetch origin refs/heads/*:refs/remotes/origin/* refs/tags/*:refs/tags/*' while working with @io_bazel_rules_go:
fatal: unable to access 'https://github.com/bazelbuild/rules_go.git/': gnutls_handshake() failed: Se recibiĆ³ un paquete TLS inesperado.
INFO: Elapsed time: 3.170s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

some help?

Source: Python Questions

LEAVE A COMMENT