Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount Google Drive from AI Platform Notebook

Is there a way to mount Google My Drive from Google's AI Platform Notebook like Google Colab?

Thanks, Jay

like image 657
jayurbain Avatar asked Apr 26 '20 23:04

jayurbain


2 Answers

Yes, there is. You can use Python package gdrivefs to mount Google Drive to AI Platform Notebook. You can find exact information for setup from PyPi project page here: https://pypi.org/project/gdrivefs/.

To install in AI Platform Notebook you need to either install it at terminal or use shell commands in Notebook. With the following commands you should be able to do it:

Install dependencies and gdrivefs package:

!sudo apt-get install -y build-essential python-dev
!pip install gdrivefs

Authenticate to your Google Drive with the link provided from first command and pass the auth token to the second command:

!gdfstool auth_get_url
!gdfstool auth_write "xxx….”

Mount and list files. You should see Google Drive content:

!gdfs -o allow_other default /mnt/gdrivefs
!ls /mnt/gdrivefs

Now you can use the mounted files as local files:

import pandas as pd
df = pd.read_csv('/mnt/gdrivefs/mydata.csv')
print(df)

If I recall correctly the performance with this method is not very good. This works at least for temporary access, small data and copying data to more suited location.

To do the same in CoLab you need only the following code. It is much simpler and more performant but unfortunately google.colab does not work in AI Platform Notebook:

from google.colab import drive
drive.mount('/mnt/drive')
like image 77
Veikko Avatar answered Oct 21 '22 18:10

Veikko


Thanks to @Veikko for his answer. I needed a slight modification. After the authentication step, I needed to create a local mount directory:

mkdir mnt/gdrivefs/

(There were permissions/ownership errors later if I created it in root). Next, I needed to modify the /etc/fuse.conf file to allow non-root users to specify mount options:

sudo nano /etc/fuse.conf and uncomment the line: user_allow_other

Then I ran the final steps (to the local mnt/gdrivefs dir) and everything worked:

!gdfs -o allow_other default mnt/gdrivefs
!ls mnt/gdrivefs
like image 1
TC Arlen Avatar answered Oct 21 '22 18:10

TC Arlen