tensorflow: ModuleNotFoundError: No module named 'google.protobuf' under Ubuntu Jammy
Click to expand!
Issue Type
Build/Install
Source
source
Tensorflow Version
v2.10.0
Custom Code
No
OS Platform and Distribution
Ubuntu 22.04.1 LTS
Mobile device
No response
Python version
3.10.6
Bazel version
5.1.1
GCC/Compiler version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
CUDA/cuDNN version
cudnn-local-repo-ubuntu2204-8.6.0.163_1.0-1_amd64
GPU model and memory
NVIDIA Corporation GM206 [GeForce GTX 950] (rev a1)
Current Behaviour?
Followed the standard instruction to compile TF from source.
The command:
bazel build --config=cuda --local_ram_resources=8192 //tensorflow/tools/pip_package:build_pip_package
fails with:
ERROR: /home/bernd/tensorflow/tensorflow/BUILD:1397:19: Executing genrule //tensorflow:tf_python_api_gen_v2 failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
2022-10-21 21:31:14.939452: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-10-21 21:31:15.169373: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
Traceback (most recent call last):
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/tools/api/generator/create_python_api.py", line 22, in <module>
from tensorflow.python.tools.api.generator import doc_srcs
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/core/framework/function_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
ModuleNotFoundError: No module named 'google.protobuf'
Target //tensorflow/tools/pip_package:build_pip_package failed to build
If I just run that script:
python /home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/core/framework/function_pb2.py
Traceback (most recent call last):
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/core/framework/function_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
ModuleNotFoundError: No module named 'tensorflow'
then protobuf can be found (my install) but not tensorflow which looks like a virtual environment issue.
Standalone code to reproduce the issue
git checkout v2.10.0
./configure
Default but with cuda = y
bazel build --config=cuda --local_ram_resources=8192 //tensorflow/tools/pip_package:build_pip_package
Relevant log output
ERROR: /home/bernd/tensorflow/tensorflow/BUILD:1397:19: Executing genrule //tensorflow:tf_python_api_gen_v2 failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
2022-10-21 21:31:14.939452: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-10-21 21:31:15.169373: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
Traceback (most recent call last):
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/tools/api/generator/create_python_api.py", line 22, in <module>
from tensorflow.python.tools.api.generator import doc_srcs
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/home/bernd/.cache/bazel/_bazel_bernd/2716ba2e215c041a26405d6ef9e43b69/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/core/framework/function_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
ModuleNotFoundError: No module named 'google.protobuf'
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/bernd/tensorflow/tensorflow/python/tools/BUILD:313:10 Middleman _middlemen/tensorflow_Spython_Stools_Ssaved_Umodel_Ucli-runfiles failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (6 by maintainers)
The Tensorflow build seems to choke on the
python3-protobufpackage for some reason. Installingprotobufvia pip fixed the issue here: