google-cloud-platform - 从 AI Platform Notebook 挂载 Google Drive

标签 google-cloud-platform google-drive-api google-api-python-client

有没有办法从像 Google Colab 这样的 Google AI Platform Notebook 挂载 Google My Drive?

谢谢,

最佳答案

就在这里。您可以使用 Python 包 gdrivefs 将 Google Drive 挂载到 AI Platform Notebook。您可以在此处从 PyPi 项目页面找到有关设置的确切信息:https://pypi.org/project/gdrivefs/ .
要在 AI Platform Notebook 中安装,您需要在终端上安装它或在 Notebook 中使用 shell 命令。使用以下命令,您应该能够做到:
安装依赖项和 gdrivefs 包:

!sudo apt-get install -y build-essential python-dev
!pip install gdrivefs
使用第一个命令提供的链接对您的 Google Drive 进行身份验证,并将身份验证 token 传递给第二个命令:
!gdfstool auth_get_url
!gdfstool auth_write "xxx….”
挂载并列出文件。您应该会看到 Google Drive 内容:
!gdfs -o allow_other default /mnt/gdrivefs
!ls /mnt/gdrivefs
现在您可以将挂载的文件用作本地文件:
import pandas as pd
df = pd.read_csv('/mnt/gdrivefs/mydata.csv')
print(df)
如果我没记错的话,这种方法的性能不是很好。这至少适用于临时访问、小数据和将数据复制到更合适的位置。
要在 CoLab 中执行相同操作,您只需要以下代码。它更简单,更高效,但不幸的是 google.colab在 AI Platform Notebook 中不起作用:
from google.colab import drive
drive.mount('/mnt/drive')

关于google-cloud-platform - 从 AI Platform Notebook 挂载 Google Drive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61449536/

相关文章:

python - Google Sheet API - 获取数据验证

google-api - 如何解决 403 错误 : User rate limit exceeded in Google Drive API?

node.js - 如何解决使用服务帐户上传时 Google Drive 存储空间超出的问题

python - Google Sheets APIv4 列分组

gmail-api - GMail API-messages()。list()仅返回消息ID

ios - Objective-C 在使用 Google Drive API 获取列表文件时使用 block

firebase - 交易可以用于收款吗?

python - os.environ.get() 使用 Google Cloud Functions 返回 None

google-cloud-platform - 谷歌云平台: Personal credentials in GCP

elasticsearch - 在多用途(即非专用)集群上运行Elasticsearch有任何不利之处吗?