如何更改Google Colab脚本在本地运行?

时间:2020-04-16 04:14:55

标签: python python-3.x google-colaboratory pydrive

我有以下在Google colab上运行的代码。我希望能够在本地运行此代码,但是我经常遇到错误。

# Auth GDrive
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# Key
downloaded = drive.CreateFile({'id': 'id1'})

# Load Up Python Files
pyDownload = drive.CreateFile({'id': 'id2'})
pyDownload.GetContentFile('file.zip')

consumer_key = ''
username = ''
private_key = downloaded.GetContentString()

关于如何使其在本地工作的任何想法?

1 个答案:

答案 0 :(得分:0)

您在代码段中引用的Colab auth模块仅在Colab后端上可用。它不能在Colab环境之外运行。

为了在本地对PyDrive进行身份验证,您需要在Google API控制台中创建OAuth客户端应用并使用生成的API凭据。 PyDrive文档在这里有一些示例:

https://pythonhosted.org/PyDrive/oauth.html