栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

如何使用google colaboratory来运行google Drive中的.py文件

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用google colaboratory来运行google Drive中的.py文件

如何使用google colaboratory来运行google Drive中的.py文件

1、使用colaboratory创建.ipynb文件

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}

3、挂载google Drive

!mkdir -p drive
!google-drive-ocamlfuse drive

4、指定云盘目录

from google.colab import drive
drive.mount("/content/drive")

5、将路径切换到需要运行的.py文件路径中

import os
path = '/content/drive/My Drive/XXXX'
os.chdir(path)
os.listdir(path)

6、运行代码

!python xxx.py

如果需要使用matlibplot绘图,则使用以下命令

%run xxx.py
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/715276.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号