Mobeen
Mobeen

Reputation: 985

Getting module 'google.protobuf.descriptor_pool' has no attribute 'Default' in my python script

I am new to python and was using a python script written by someone else. I was running it fine in a different PC. Just had to install coupe of packages including pip3, google-cloud, google-cloud-bigquery and pandas.

Now when I installed the same packages on a different PC, I am unable to run the script. It is showed the following error first:

module = 'google.protobuf.descriptor_pb2' TypeError: expected bytes, Descriptor found

However, when In purged/re-installed/updated packages and also added protobuf3 and protobuf-py3 package, The error has been updated to the following message:

from google.cloud import bigquery
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/bigquery/__init__.py", line 35, in <module>
    from google.cloud.bigquery.client import Client
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/bigquery/client.py", line 50, in <module>
    import google.cloud._helpers
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/_helpers.py", line 33, in <module>
    from google.protobuf import duration_pb2
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/protobuf/duration_pb2.py", line 8, in <module>
    from google.protobuf import symbol_database as _symbol_database
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/protobuf/symbol_database.py", line 193, in <module>
    _DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: module 'google.protobuf.descriptor_pool' has no attribute 'Default'

.Any help or leads in this will be appreciated

Upvotes: 13

Views: 14142

Answers (5)

Leonardo Sarmiento
Leonardo Sarmiento

Reputation: 31

I solved it by first executing twice

pip3 uninstall protobuf

The second time the terminal returned

Found existing installation: protobuf 3.6.1
Not uninstalling protobuf at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'protobuf'. No files were found to uninstall.

Then I removed protobuf manually

sudo rm -r /usr/lib/python3/dist-packages/google/protobuf*
sudo rm -r /usr/lib/python3/dist-packages/protobuf*

And finally I executed

pip3 install --upgrade protobuf

And the problem was solved

Upvotes: 3

Andrew
Andrew

Reputation: 37969

The reason can be that the interpreter that you are using to run the python programm uses the previous version of google.protobuf

You can assure it to run in the interpreter

>>> import google.protobuf
>>> print google.protobuf.__version__

Then compare it running in the terminal

$pip show protobuf

If the versions are different that's the reason

So I suggest deleting this package right from the python interpreter console

>>> pip uninstall protobuf -y

After you can even install the package right from the python console

>>> pip install protobuf

After that you good to go ✌️

Upvotes: 0

abdou_dev
abdou_dev

Reputation: 827

I solved the problem by uninstalling protobuf:

pip3 uninstall protobuf

pip3 uninstall python3-protobuf

NB: You should repeat this command until you get a message that there is no package named protobuf.

After that execute:

pip3 install protobuf

Install just the protobuf , don't install python3-protobuf

Hope this solution can help you.

Upvotes: 14

Amit Maimon
Amit Maimon

Reputation: 21

Actually I've ran into a similar case, we had 2 packages installed protobuf and python3-protobuf. I actually dont know the root cause for this but apparently when you do that:

pip install protobuf
pip install python3-protobuf

that error you described is happening, looks like it gives you some different version, like those two packages have overlapping files, and they override each other or something.

the solution for me was simply to reverse the installation order (make sure to uninstall them both first):

pip install python3-protobuf
pip install protobuf

or just

pip install python3-protobuf protobuf

hope this helps anyone here.

Upvotes: 0

Hyperion
Hyperion

Reputation: 168

Did you try this too?

"I solved the problem of showed Attribute Error: 'module' object has no attribute 'Default' when import tensorflow after installed by delete redundant protobuf file.

The reason is some google/protobuf/descriptor_pool.py do not have a 'Default' defined. This usually happened at old version of protobuf so I upgraded successfully, but problem not solved. And by checking PATH and search about 'google/protobuf', I found it existed in both "/usr/local/lib/python2.7/dist-packages/google/protobuf/" and "/usr/lib/python2.7/dist-packages/google/protobuf/". Previous one have attribute 'Default' but the second one not. I tried import google.protobuf and google.protobuf.file, It shows '/usr/lib/python2.7/dist-packages/google/protobuf/init.pyc'. I deleted /usr/lib/python2.7/dist-packages/google/protobuf and tried to import tensorflow, worked."

Upvotes: 0

Related Questions