4

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

2 Answers2

5
# 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
Mr.Spock
  • 59
  • 1
  • 3
  • Please clarify the link for the pip3.6 as follows: `https://bootstrap.pypa.io/pip/3.6/get-pip.py`. The one mentioned in answer is already for `3.7` or later versions – nicolay-r Jan 26 '23 at 11:55
3

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
  • 1
    It is likely that colab has just recently drop the support of `python 3.6.9`, so now this list does not provide such alternative – nicolay-r Jan 26 '23 at 11:38