Changing the Python version on Google Colab

and associated issues

Siladittya Manna
The Owl
Sep 27, 2023

--

If you log in to Colab (as of the date of writing this article), the Python version we get is 3.10. However, we may require a different version of Python to reproduce the results of a paper because of the dependency of a library. Let’s see how we can do that in some simple steps.

Step 1:

!apt-get update -y

Step 2:

Suppose we want to install Python-3.8

!apt-get install python3.8 python3.8-distutils

Step 3:

!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

Step 4:

!update-alternatives --config python3

Step 5:

!apt-get install python3-pip
!python3 -m pip install --upgrade pip --user

Now you are good to go!

If we don't install python3.8-distutils, then we will get the error shown below when upgrading pip.

ModuleNotFoundError: No module named ‘distutils.cmd’

--

--

Siladittya Manna
The Owl

Senior Research Fellow @ CVPR Unit, Indian Statistical Institute, Kolkata || Research Interest : Computer Vision, SSL, MIA. || https://sadimanna.github.io