[英]Access BigQuery data from Jupyter Notebook in AI Platform Google Cloud
[英]Accessing Google Cloud Storage from local Jupyter and Notebooks in Google AI Platform / Vertex AI
问题陈述:让谷歌云存储和一些桶。 需要将此类存储桶中的数据导入到:
任何能够处理这些情况的参考代码将不胜感激。 亲切的问候
本地 Jupyter 实例:首先使用gcloud auth login验证您的本地环境,然后使用gsutil将内容复制到本地环境。
# Authenticate with your account
!gcloud auth login --no-browser
# Copy from your bucket to local path (note -r is for recursive call)
!gsutil cp -r gs://BUCKET/DIR_PATH ./TARGET_DIR
Colab :首先验证您的 Colab session 以访问云 API。然后您可以使用gsutil
将内容复制到本地环境。
# Authenticate with your account
from google.colab import auth as google_auth
google_auth.authenticate_user()
# Copy from your bucket to local path (note -r is for recursive call)
!gsutil cp -r gs://BUCKET/DIR_PATH ./TARGET_DIR
Vertex AI 中的 JupyterLab 笔记本:您的环境已经过身份验证。 使用 gsutil 将内容复制到本地环境。
# Copy from your bucket to local path (note -r is for recursive call)
!gsutil cp -r gs://BUCKET/DIR_PATH ./TARGET_DIR
您还可以使用Cloud Storage 客户端库通过 Python 直接访问 Google Cloud Storage 中的文件。 如上所述,您需要首先对您的环境进行身份验证。
# Imports the Google Cloud client library
from google.cloud import storage
# Instantiates a client
storage_client = storage.Client()
# The name for the new bucket
bucket_name = "my-new-bucket"
# Creates the new bucket
bucket = storage_client.create_bucket(bucket_name)
print(f"Bucket {bucket.name} created.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.