Forums

How to import bigquery

I'm trying to use bigquery as part of a simple project - although I'm ultimately going to transfer the database tables to pythonanywhere in due course.

However, I've tried to use the following import:

from google.cloud import bigquery

But not sure what the error means.

2023-12-28 12:14:47,104: Error running WSGI application
2023-12-28 12:14:47,105: TypeError: Descriptors cannot be created directly.
2023-12-28 12:14:47,105: If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
2023-12-28 12:14:47,105: If you cannot immediately regenerate your protos, some other possible workarounds are:
2023-12-28 12:14:47,105:  1. Downgrade the protobuf package to 3.20.x or lower.
2023-12-28 12:14:47,105:  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
2023-12-28 12:14:47,106: 
2023-12-28 12:14:47,106: More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
2023-12-28 12:14:47,106:   File "/var/www/elksie5000_pythonanywhere_com_wsgi.py", line 16, in <module>
2023-12-28 12:14:47,106:     from flask_app import app as application
2023-12-28 12:14:47,106: 
2023-12-28 12:14:47,106:   File "/home/elksie5000/mysite/flask_app.py", line 5, in <module>
2023-12-28 12:14:47,106:     from google.cloud import bigquery
2023-12-28 12:14:47,106: 
2023-12-28 12:14:47,107:   File "/home/elksie5000/.local/lib/python3.9/site-packages/google/cloud/bigquery/__init__.py", line 35, in <module>
2023-12-28 12:14:47,107:     from google.cloud.bigquery.client import Client
2023-12-28 12:14:47,107: 
2023-12-28 12:14:47,107:   File "/home/elksie5000/.local/lib/python3.9/site-packages/google/cloud/bigquery/client.py", line 52, in <module>
2023-12-28 12:14:47,107:     import google.api_core.exceptions as core_exceptions
2023-12-28 12:14:47,107: 
2023-12-28 12:14:47,107:   File "/home/elksie5000/.local/lib/python3.9/site-packages/google/api_core/exceptions.py", line 29, in <module>
2023-12-28 12:14:47,107:     from google.rpc import error_details_pb2
2023-12-28 12:14:47,107: 
2023-12-28 12:14:47,107:   File "/usr/local/lib/python3.9/site-packages/google/rpc/error_details_pb2.py", line 50, in <module>
2023-12-28 12:14:47,107:     _descriptor.FieldDescriptor(
2023-12-28 12:14:47,108: 
2023-12-28 12:14:47,108:   File "/home/elksie5000/.local/lib/python3.9/site-packages/google/protobuf/descriptor.py", line 553, in __new__
2023-12-28 12:14:47,108:     _message.Message._CheckCalledFromGeneratedFile()
2023-12-28 12:14:47,108: ***************************************************
2023-12-28 12:14:47,108: If you're seeing an import error and don't know why,
2023-12-28 12:14:47,108: we have a dedicated help page to help you debug: 
2023-12-28 12:14:47,108: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-12-28 12:14:47,108: ***************************************************

Follow the instruction on top of your error log. You have "More information" section there.

I tried downgrading protobuf and installed protoc but still no joy.

Did you regenerate the code?

How do I do that?

I downgraded protobuf, added the parameter to the .bashrc, installed protoc. But I can't find any protoc files that I could run to regenerate code.

In that case, you can use the second option and use pure python parsing.