如何跨会话保存安装? [英] How to save installations across sessions?

查看:60
本文介绍了如何跨会话保存安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Colaboratory中,有没有一种方法可以保存跨会话的库安装?如果可以,我该怎么办?我想总体上了解有关协作会话管理的更多信息.

In Colaboratory, is there a way to save library installations across sessions? If so how, can I do that? I'd like to learn more about Colaboratory session management in general.

目前,每次我必须导入时,例如一个cv2模块(因为默认情况下不可用),我需要通过!apt=-get package-name重新安装带有!pip install opencv-python的模块以及提供共享库的依赖项.

Currently, everytime I have to import, for e.g. a cv2 module(as this is not available by default), I need to reinstall the module with !pip install opencv-python along with it's dependencies that provide for shared objects, through a !apt=-get package-name.

推荐答案

VM闲置一段时间后会超时,因此,您需要构造笔记本以在需要时安装自定义依赖项.

VMs time out after a period of inactivity, so you'll want to structure your notebooks to install custom dependencies if needed.

典型的模式是在笔记本顶部有一个单元,根据需要执行aptpip安装命令.

A typical pattern is to have a cell at the top of your notebook that executes apt and pip install commands as needed.

对于opencv,它看起来像:

In the case of opencv, that would look something like:

!apt install -y -qq libsm6 libxext6 && pip install -q -U opencv-python

(在新的VM上大约需要7秒钟.)

(Takes ~7 seconds for me on a fresh VM.)

这篇关于如何跨会话保存安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆