gpt4 book ai didi

google-colaboratory - 在 google colab 中挂载多个驱动器

转载 作者:行者123 更新时间:2023-12-03 22:55:26 25 4
gpt4 key购买 nike

我使用这个功能来挂载我的谷歌驱动器

from google.colab import drive
drive.mount('/content/drive', force_remount=True)

然后像这样从中复制文件
!tar -C "/home/" -xvf '/content/drive/My Drive/files.tar'

我想从 2 个驱动器复制文件,但是当我尝试运行第一个脚本时,它只是重新安装了我的第一个驱动器

如何安装第一个驱动器,复制文件,然后安装另一个驱动器并从第二个驱动器复制文件?

最佳答案

以防万一有人真的需要安装多个驱动器,这里有一个安装 2 个驱动器的解决方法。

首先,使用挂载第一个驱动器

from google.colab import drive
drive.mount('/drive1')

然后,使用以下脚本挂载第二个驱动器。

!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}
!mkdir -p /drive2
!google-drive-ocamlfuse /drive2

现在,您将能够从 /drive1/My Drive/ 访问第一个驱动器中的文件。以及来自 /drive2/ 的第二个驱动器的那些(第二种方法不会自动创建 My Drive 文件夹)。
干杯!

趣闻:第二种方法其实是谷歌推出 google.colab.drive之前在Colab环境中挂载谷歌硬盘的常用方法。

关于google-colaboratory - 在 google colab 中挂载多个驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53728127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com