2019年6月5日
Colaboratory 连接Google Drive
方法一
!echo 'Mounting...'
from google.colab import drive
drive.mount('/content/drive/')
!ls '/content/drive/My Drive'
!echo 'Mounted'
方法二:
!echo 'Installing required software'
!apt-get install -y -qq software-properties-common module-init-tools 2>&1 > /dev/null
!echo 'Add apt-repository with Google.Drive Fuse'
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!echo 'Updating packages...'
!apt-get update -y -qq
!echo 'Installing google-drive-ocamlfuse fuse...'
!apt-get install -y -qq google-drive-ocamlfuse fuse
!echo 'Authenticate Fuse in Google.Drive...'
from google.colab import auth
from oauth2client.client import GoogleCredentials
import getpass
auth.authenticate_user()
creds = GoogleCredentials.get_application_default()
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass('Enter auth code here: ')
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
!echo 'Authenticated!'
!echo 'Creating mount directory'
!mkdir ./drive2
!echo 'Mounting...'
!google-drive-ocamlfuse ./drive2
!ls ./drive2
!echo 'Mounted!'