Is there a way to mount Google My Drive from Google's AI Platform Notebook like Google Colab?
Thanks, Jay
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')
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With