Colaboratory挂载谷歌云盘

# 授权绑定Google Drive
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
# 指定Google Drive云端硬盘的根目录,名为drive
!mkdir -p drive
!google-drive-ocamlfuse drive
# 指定当前的工作目录
import os

# 此处为google drive中的文件路径,drive为之前指定的工作根目录,要加上
os.chdir("drive/.../...") 
# 查看文件目录,是否包含所需的文件
!ls

参考博客:https://www.jianshu.com/p/ce2e63d1c10c

你可能感兴趣的:(Colaboratory挂载谷歌云盘)