google.colab挂载google drive

why?

google.drive是个云盘,挂载了google.drive就可以上传自己的文件,代码跑项目文件,虽然免费空间只有15G,跑跑demo还是够用了的

授权

2次复制验证码

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
#为挂载goolge drive做准备

 

挂载

!mkdir -p drive 
!google-drive-ocamlfuse drive -o nonempty #如果已经开启,就要加上参数 -o nonempty ,表示可以挂载包含文件的文件夹

 

注意事项 

容易再登录就连接不上

解决:保存code随时连接

google.drive上传文件问题

有时候google.drive上反复上传相同文件夹(文件)会出问题(命名)

解决:删除文件前先在google.drive中重命名,之后再删除重新上传

可以用 !ls 检查

 

posted @ 2020-08-02 17:14  aha是Q啊  阅读(420)  评论(0)    收藏  举报