Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 841
Mobeen Avatar asked Jan 25 '20 14:01

Mobeen


1 Answers

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

like image 131
Leonardo Sarmiento Avatar answered Oct 26 '22 00:10

Leonardo Sarmiento