问题
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