I'm using Google Colab and need to restart my notebook at least once a day due to their usage limits.
To mount my Google Drive I have the following code:
from google.colab import drive
drive.mount('drive')
I then get a prompt:
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=xxxxxxxxx....
Enter your authorization code: ___________________________________________________
How can I authorise only once and have that authorisation remembered?
Ideally, that authorisation will have already happened as I'm signed in to Gmail and I can just specify the account email address of the Drive to mount.
However any solution of persistent authorisation where I don't store the auth code in the notebook would be great.
Automatically mounting to your Drive files is now supported for Colab notebooks which aren't shared by multiple people. To enable this for a notebook, create a new Drive notebook, open the file browser, and click the 'Mount Drive' button.
Colab Pro limits RAM to 32 GB while Pro+ limits RAM to 52 GB. Colab Pro and Pro+ limit sessions to 24 hours. Colab Pro does not provide background execution, while Pro+ does. Colab Pro and Pro+ do not offer a full version of JupyterLab.
Also, runtimes are longer in the pro version and instances are connected for up to 24 hours. In the free version, runtimes are limited to 12 hours and RAM is also limited to 16 GB.
You can't set it to only authenticate once and stay that way for a new runtime, because Colab runs on a VM that is recycled periodically. You can make sure force_remount
is set to False
so it doesn't unnecessarily ask you to reauthorize:
drive.mount('/content/gdrive', force_remount=False)
But any time you reset the runtime, you will need to reauthenticate with a different authorization code.
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