1. ホーム
  2. テンソルフロー

Tensorflow protobufのバージョンエラー対策 (AttributeError: 'module' オブジェクトに 'Default' 属性がない)

2022-01-24 10:16:38
うっかりしていると、TFが実行されず、報告されたエラーは
AttributeError: 'module' object has no attribute 'Default'
as follows.

>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 75, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 9, in < module>
    from google.protobuf import symbol_database as _symbol_database
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/symbol_database.py", line 165, in <module>
    _DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: 'module' object has no attribute 'Default'
There are various solutions online for this problem, but they are never right.
This is a solution like pip install --upgrade protobuf, but it still doesn't work after that.
Later, I went to /usr/loca/lib/python3.6/site-packages/ and found that there are several versions of protobuf, including 3.2 and 3.4.

I had no choice but to look at https://github.com/tensorflow/tensorflow/releases中关于protobuf的相关说明 and found that the version of protobuf required for tf is 3.0.0b2.

https://pypi.python.org/pypi/protobuf/3.0.0b2, downloaded the WHL file from this site, and installed it, and it worked fine. Solved the problem.







>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 75, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 9, in < module>
    from google.protobuf import symbol_database as _symbol_database
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/symbol_database.py", line 165, in <module>
    _DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: 'module' object has no attribute 'Default'


There are various solutions online for this problem, but they are never right.

This is a solution like pip install --upgrade protobuf, but it still doesn't work after that.

Later, I went to /usr/loca/lib/python3.6/site-packages/ and found that there are several versions of protobuf, including 3.2 and 3.4.

I had no choice but to look at https://github.com/tensorflow/tensorflow/releases中关于protobuf的相关说明 and found that the version of protobuf required for tf is 3.0.0b2.

https://pypi.python.org/pypi/protobuf/3.0.0b2, downloaded the WHL file from this site, and installed it, and it worked fine. Solved the problem.