How to permanently install package in GoogleColab using conda?

Viewed 3528

I am trying yo use a PyTorch library SparseConvNet (https://github.com/facebookresearch/SparseConvNet) in Google Colaboratory. In order to install it properly, you need to first install Conda, and then using Conda install the SparseConvNet package. Here is the code I am using (following the instructions from scn readme file):

!wget -c https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
!chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
!bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -f -p /usr/local

import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')

!conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
!conda install google-sparsehash -c bioconda
!conda install -c anaconda pillow

!git clone https://github.com/facebookresearch/SparseConvNet.git
!cd SparseConvNet/
!bash develop.sh

When I run this it is working and I can successfully import sparseconvnet package, but I need to do it every time I enter the notebook or restart runtime, and it's taking a lot of time. Is it possible to install these packages permanently?

There is one similar question, and the answer suggest that I should install it on my drive, but I don't know how to do it using conda. Thanks!

3 Answers

You can specify the directory for conda to install to using

conda install -p path_to_your_dir

So, you can mount your google drive and conda install there to make it permanent.

The whole environment that Google Colaboratory runs your notebooks is not permanent, it is one of their premises. If you need a persistent environment consider running Jupyter directly on a Google Cloud Compute Engine VM, they have pre-built images with everything configured here or Google Cloud Datalab (which runs on a GCE VM, but is managed)

Unfortunately no. Google colab machine will erase after some time. It is a docker inside, and every time you start the GC it will start a new docker image. But you can connect to your local machine via colab. Check the option on Connect button.

Related