如何将文件从Colab输出到google团队(共享)驱动器?

2024-06-16 17:13:14 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试将一些pickle文件从Colab输出到google团队(共享)驱动器。请注意,团队驱动由其他人拥有

我知道如何输出文件到我的谷歌驱动器从Colab,一个问题是经常被问到的论坛。但是,我还没有看到任何关于如何输出到团队驱动的相关问题/答案

以下代码用于将文件输出到驱动器(我的):

  1. 创建picke文件
import pickle
from google.colab import files
a_file = a_fun(a)

# save pickle in VM temporary
with open('a_file.pickle', 'wb') as handle:
    pickle.dump(a_file, handle, protocol=pickle.HIGHEST_PROTOCOL)
  1. 包装班奇及相关Colab和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}
  1. 让我自己开车
!mkdir -p my_Drive 
!google-drive-ocamlfuse my_Drive 
  1. 将文件复制到驱动器
!cp /content/a_file.pickle /content/Drive
print('output file success')

有没有一种方法可以做一个类似的技巧,以团队驱动

我怀疑授权有问题。因为在将文件输出到我自己的驱动器的情况下,它需要授权代码来访问我的驱动器


Tags: 文件importclientidgetgoogleaptdrive