从源代码构建时,如何在Colab中永久安装诸如opencv之类的库?

时间:2019-09-03 10:35:47

标签: python opencv google-colaboratory

我必须尝试在colab中的github上运行特定项目的代码,但似乎它需要从源代码构建的opencv才能运行而不会产生错误。对我而言,在colab上构建opencv大约需要3个小时,因此我正在寻找将其永久安装在colab上的方法。是否可以将其安装在Google驱动器上?如果是,那么如何使驱动器上安装的opencv对在colab上运行的代码“可见”?

1 个答案:

答案 0 :(得分:0)

请遵循以下步骤:
1。使用您的gmail ID进行Google身份验证:

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

2。为您的操作创建驱动器:

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

3。如果未安装,请安装opencv lib或导入opencv

import cv2