【发布时间】:2016-10-14 01:07:04
【问题描述】:
我有一个使用 Pandas 作为工具访问 Big Query 的 Jypyter Notebook:
df = pd.io.gbq.read_gbq( query, project_id = 'xxxxxxx-xxxx' )
这在我的本地机器上运行良好! (太好了,事实上!) 但是,当我将同一个笔记本加载到 Cloud DataLab 时,我得到:
DistributionNotFound: google-api-python-client
这似乎相当令人失望!我相信该模块应该与 Pandas 一起安装。但不知何故谷歌不包括它? 出于多种原因,最好不必将我们在本地机器上开发的代码更改为 Cloud DataLab 中需要的代码,在这种情况下,我们会大量参数化数据访问......
好的,我跑了:
!pip install --upgrade google-api-python-client
现在,当我运行笔记本时,我收到一个身份验证提示,由于 DataLab 位于远程计算机上,因此我无法解决:
Your browser has been opened to visit:
>>> Browser string>>>>
If your browser is on a different machine then exit and re-run this
application with the command-line parameter
--noauth_local_webserver
对此没有明显的答案?
在更新笔记本中的 google-api-python-client 后,我在同一笔记本中使用@Anthonios Partheniou 建议的以下代码(在单元块中执行它) 我得到了以下回溯:
TypeError Traceback (most recent call last)
<ipython-input-3-038366843e56> in <module>()
5 scope='https://www.googleapis.com/auth/bigquery',
6 redirect_uri='urn:ietf:wg:oauth:2.0:oob')
----> 7 storage = Storage('bigquery_credentials.dat')
8 authorize_url = flow.step1_get_authorize_url()
9 print 'Go to the following link in your browser: ' + authorize_url
/usr/local/lib/python2.7/dist-packages/oauth2client/file.pyc in __init__(self, filename)
37
38 def __init__(self, filename):
---> 39 super(Storage, self).__init__(lock=threading.Lock())
40 self._filename = filename
41
TypeError: object.__init__() takes no parameters
他提到需要从同一个文件夹中执行笔记本,但我知道执行数据实验室笔记本的唯一方法是通过 repo?
虽然使用新 Jupyter Datalab 模块的新模块是一种可能的替代方案,但在本地和 DataLab 实例上使用完整的 Pandas BQ 界面的能力将非常有帮助!因此,请尽情寻找解决方案!
pip installed:
GCPDataLab 0.1.0
GCPData 0.1.0
wheel 0.29.0
tensorflow 0.6.0
protobuf 3.0.0a3
oauth2client 1.4.12
futures 3.0.3
pexpect 4.0.1
terminado 0.6
pyasn1 0.1.9
jsonschema 2.5.1
mistune 0.7.2
statsmodels 0.6.1
path.py 8.1.2
ipython 4.1.2
nose 1.3.7
MarkupSafe 0.23
py-dateutil 2.2
pyparsing 2.1.1
pickleshare 0.6
pandas 0.18.0
singledispatch 3.4.0.3
PyYAML 3.11
nbformat 4.0.1
certifi 2016.2.28
notebook 4.0.2
cycler 0.10.0
scipy 0.17.0
ipython-genutils 0.1.0
pyasn1-modules 0.0.8
functools32 3.2.3-2
ipykernel 4.3.1
pandocfilters 1.2.4
decorator 4.0.9
jupyter-core 4.1.0
rsa 3.4.2
mock 1.3.0
httplib2 0.9.2
pytz 2016.3
sympy 0.7.6
numpy 1.11.0
seaborn 0.6.0
pbr 1.8.1
backports.ssl-match-hostname 3.5.0.1
ggplot 0.6.5
simplegeneric 0.8.1
ptyprocess 0.5.1
funcsigs 0.4
scikit-learn 0.16.1
traitlets 4.2.1
jupyter-client 4.2.2
nbconvert 4.1.0
matplotlib 1.5.1
patsy 0.4.1
tornado 4.3
python-dateutil 2.5.2
Jinja2 2.8
backports-abc 0.4
brewer2mpl 1.4.1
Pygments 2.1.3
结束
【问题讨论】:
-
我无法产生异常。您能否运行以下命令并使用 oauth2client 版本进行回复?运行
import oauth2client,然后运行oauth2client.__version__ -
同时运行
import pip,然后运行for dist in pip.get_installed_distributions(): print dist -
导入 oauth2client 2 oauth2client.__version__ '1.4.12'
-
上面的Pip安装列表
-
我使用datalab.cloud.google.com 部署了一个干净的datalab 实例,并且我在答案中提供的代码有效。我注意到的一件事是,在我已安装的 python 模块列表中,我看到了
google-api-python-client 1.5.1,但在您提供的输出中我没有看到google-api-python-client。
标签: python pandas google-bigquery google-cloud-datalab