how to use python 3.6 in google Colab

Question:

I want to work with python 3.6 due to some file compatibility issue, can anyone help me out, where I can use python 3.6 in google Colab, apart from that I want to use tensorflow 2.0 and opencv 4.0.0.21, which I have already install in Colab am only stuck with python 3.6. any help would be appreciated

Answers:

You can use the command below and then select the alternative version to change the python version.

!sudo update-alternatives --config python3

Output:

There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.7   2         auto mode
  1            /usr/bin/python3.6   1         manual mode
  2            /usr/bin/python3.7   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in manual mode 

To check the python version use the following code.

python --version # 3.6.9
Answered By: Tfer3
# first install python 3.6
!sudo apt-get update -y
!sudo apt-get install python3.6
# change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
# select python version
!sudo update-alternatives --config python3
# check python version
!python --version
# install pip for new python 
!sudo apt-get install python3.6-distutils
!wget https://bootstrap.pypa.io/get-pip.py
!python get-pip.py
# upgrade pip
!sudo apt install python3-pip
!python -m pip install --upgrade pip
Answered By: Mr.Spock