On local development app-engine server(and on production app engine), I want to run a script which has big-query related code, but I am getting an error. I have already visited all the answers related to this error in stackoverflow but did not find anything workable. following is the code and error that occurred. Thanks in advance for your precious time.
Code
#!/usr/bin/python
from google.cloud import bigquery
client = bigquery.Client('myproject')
query = '(SELECT *FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY tb1.user_id ORDER BY tb1.timestamp DESC) AS RowNo FROM `mytable` tb1) x WHERE x.RowNo = 1)'
job_config = bigquery.QueryJobConfig()
job_config.allow_large_results = True
job_config.destination = dest_table_ref
job_config.write_disposition = 'WRITE_TRUNCATE'
query_job = client.query(query, job_config=job_config)
When I hit the url (http://myproject:8080/cronscript) I get following errors
Error
File "/home/username/src/project-name/python_reporting-2017-12-15-10-37/cronscript.py", line 3, in from google.cloud import bigquery File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1132, in load_module raise ImportError('No module named %s' % fullname) ImportError: No module named google.cloud.bigquery
However, when I open python shell by typing python and then if I type
from google.cloud import bigquery
it works fine. If I run python cronscript.py it also gets executed properly $ python cronscript.py Done $
Only when I execute this from a local app server after performing dev_appserver.py app.yaml I receive above error.
What all I have already tried
1) sudo pip install --upgrade google-cloud-bigquery
2) my requirements.txt look like
google-api-python-client
google-cloud
3) pip install -t lib/ requirements.txt
4) from google.appengine.ext import vendor
vendor.add('lib')
5) from __future__ import absolute_import
Still unresolved.