Sometimes it’s necessary to downgrade packages in google colab to restore compatibility with an older version (e.g. pytorch). One way of doing this is using conda within colab and a few tricks make this work. Here is the colab notebook:

Here a quick code gist:

#Check Python version of colab - we need to match this in conda:
!python --version


!which conda # should return /usr/local/bin/conda
!conda --version # should return 4.10.3
!python --version # should return 3.7.10 but should actually match the one installed in colab, which is currently: 3.7.11

conda install --channel defaults conda python=3.7 --yes
conda update --channel defaults --all --yes

!conda --version # now returns 4.11.0
!python --version # now matches with colab :) 3.7.11

!yes | conda install pytorch==1.6.0 torchvision==0.7.0 -c pytorch

import sys
sys.path # dist-packages is colab and site-packages is conda -> problem is that colab packages get loaded before conda


# So this will now use conda's torch with cuda 10
import torch


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.