Max*_*wer 1 python mount-point google-drive-api google-colaboratory
我正在尝试安装一个目录以https://drive.google.com/drive/folders/my_folder_name在 google colab 笔记本中使用。
安装文件夹的说明显示了以 /content/drive 开头的目录示例:
from google.colab import drive
drive.mount('/content/drive')
Run Code Online (Sandbox Code Playgroud)
但我的目录不以 开头/content/drive,并且我尝试过的以下操作均导致ValueError: Mountpoint must be in a directory that exists:
drive.mount("/content/drive/folders/my_folder_name")
drive.mount("content/drive/folders/my_folder_name")
drive.mount("drive/folders/my_folder_name")
drive.mount("https://drive.google.com/drive/folders/my_folder_name")
Run Code Online (Sandbox Code Playgroud)
如何安装不以 开头的 google 驱动器位置/content/drive?
中的路径drive.mount('/content/drive')是在笔记本运行的虚拟框中安装 GDrive 的路径(安装点)(请参阅 Unix/Linux 中的“安装点”)。它并不指向您尝试访问 Google 云端硬盘的路径。保持"/content/drive"原样并像这样工作:
from google.colab import drive
drive.mount("/content/drive") # Don't change this.
my_path = "/path/in/google_drive/from/root" # Your path
gdrive_path = "/content/drive" + "/My Drive" + my_path # Change according to your locale, if neeeded.
# "/content/drive/My Drive/path/in/google_drive/from/root"
Run Code Online (Sandbox Code Playgroud)
并修改my_path为位于 GDrive 中的所需文件夹(我不知道是否会"/My Drive/"根据您的区域设置进行更改)。现在,Colab Notebooks 默认保存笔记本,就"/Colab Notebooks"我而言,我的 GDrive 的根实际上是gdrive_path = "/content/drive/My Drive"(我猜你的也是)。这给我们留下了:
import pandas as pd
from google.colab import drive
drive.mount("/content/drive") # Don't change this.
my_path = "/folders/my_folder_name" # THIS is your GDrive path
gdrive_path = "/content/drive" + "/My Drive" + my_path
# /content/drive/My Drive/folders/my_folder_name
sample_input_file = gdrive_path + "input.csv" # The specific file you are trying to access
rawdata = pd.read_csv(sample_input_file)
# /content/drive/My Drive/folders/my_folder_name/input.csv
Run Code Online (Sandbox Code Playgroud)
成功挂载后,在授予drive.mount API 权限后,系统会要求您粘贴验证代码。
更新:GColab 不再需要复制/粘贴代码,而是通过通常的 Google 登录页面简单地确认您的身份。
| 归档时间: |
|
| 查看次数: |
19648 次 |
| 最近记录: |