How to deal with packages mounted to google drive in colab

Viewed 164

I'm running Google Colab Pro, and I wanted to start mounting my gDrive to avoid having to reinstall my packages every time I start a new runtime. I've used some code I found a while ago on overflow

import os, sys
from google.colab import drive
drive.mount('/content/mnt')
nb_path = '/content/notebooks'
os.symlink('/content/mnt/My Drive/Colab Notebooks', nb_path)
sys.path.insert(1, nb_path)  # or append(nb_path)

Which runs fine. My sys path order is:

['',
 '/content/notebooks',
 '/content',
 '/env/python',
 '/usr/lib/python37.zip',
 '/usr/lib/python3.7',
 '/usr/lib/python3.7/lib-dynload',
 '/usr/local/lib/python3.7/dist-packages',
 '/usr/lib/python3/dist-packages',
 '/usr/local/lib/python3.7/dist-packages/IPython/extensions',
 '/root/.ipython']

For example, JAX==0.2.13 is a pre-installed library in colab. I want to downgrade to use xmaps.

!pip install jax==0.2.12 --target=$nb_path

I expect jax to install in $nb_path as 0.2.12, and when I go to retrieve them, I want python to look at $nb_path first and find it there.

I have also tried using any combination of

!export PYTHONPATH=$nb_path:$PYTHONPATH,

and messing around with pip --target directory.

At the end of the day, I want to run a little block of code at the start of every notebook that sets all of my package defaults to my gDrive. I have 100gb of gdrive space solely dedicated to my colab, idk if that provides flexibility to the solution.

0 Answers
Related