Google免费GPU使用教程(Google Colab Colaboratory)

参考:

https://www.234du.com/1154.html

https://mp.weixin.qq.com/s/TGTToLYSQJui94-bQC4HIQ

注册gmail时遇到手机号无法发送短信问题,请切换IE浏览器重试。


0、新建 XXXX.ipynb文件,打开文件

  修改-》笔记本设置,选择python版本,以及GPU/TPU

1、使用Google Colab运行py文件,读取和存储到Google云盘中

首先运行这些代码,以便安装必要的库并执行授权。

运行以下代码:

!apt-get install net-tools

 !apt-get update
 !apt-get upgrade

!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}

 注:!pip install或者 !apt-get install命令可以安装其他能使用到的库。 

保持gmail登陆状态,第二行命令执行过程中需要打开url获取验证码填入,回车。

2、挂载Google Drive
执行如下代码:
!mkdir -p drive
!google-drive-ocamlfuse drive

挂载完成后就可以使用Google云盘中的文件了,(因为这个jupyter笔记本设置的是python3所以下面事例用python3),如:

!python3 drive/app/xxx.py

3、更改工作目录

查看工作目录:

!ls  

更改工作目录:

import os
os.chdir("drive/app")

  


其它:

Package has no installation candidate解决方法

问题:

#  apt-get install <packagename>
Reading package lists... Done
Building dependency tree... Done
Package aptitude is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package <packagename> has no installation candidate

解决方法如下:
# apt-get update
# apt-get upgrade
# apt-get install <packagename>

这样就可以正常使用apt-get了~

  

猜你喜欢

转载自www.cnblogs.com/xianhan/p/10142706.html