How to save installations across sessions?

筅森魡賤 提交于 2019-12-11 12:09:29

问题


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.

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.


回答1:


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

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

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

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

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



来源:https://stackoverflow.com/questions/47428195/how-to-save-installations-across-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!